System Commands in PForth

146 views
Skip to first unread message

MichaelM

unread,
Oct 2, 2016, 2:38:19 PM10/2/16
to pforthdev
Hello Everyone,

I am new to the group. I'm trying to implement a glue routine for running bash commands from Pforth on my mac. I've just started programming in C. I know a Forth string address points to the count byte, but I'm not sure how to convert it to a C string and call system(). Here is what I have tried in pfcustom.c , with the various components separated by dashes:

------
#include <stdlib.h>
-------
static void Shell( const char *Val3 );
-------
static void Shell( const char *Val3 )
{


   
int system( const char *Val3 );


}
-------
CustomFunctionTable[2] = Shell;
-------
(CFunc0) Shell
-------
 err
= CreateGlueToC( "SHELL", i++, C_RETURNS_VOID, 1 );
   
if( err < 0 ) return err;
-------


It compiles fine, but doesn't produce the desired result. My test goal is to have the directory listing appear in the terminal within Pforth. Any ideas or suggestions you may have would be greatly appreciated!

Thank you,

Michael

Phil Burk

unread,
Oct 3, 2016, 11:58:37 AM10/3/16
to pfor...@googlegroups.com
Hello Michael,

Welcome to the list.

 I know a Forth string address points to the count byte, but I'm not sure how to convert it to a C string

Check out the ForthStringToC() function here:

If your Forth terminal is just stdout then the results of the system call should just show up. But if you are drawing Forth output in a graphics window then you may need to redirect stdout to your own text handler.

Phil Burk



--
You received this message because you are subscribed to the Google Groups "pforthdev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pforthdev+unsubscribe@googlegroups.com.
To post to this group, send email to pfor...@googlegroups.com.
Visit this group at https://groups.google.com/group/pforthdev.
For more options, visit https://groups.google.com/d/optout.

MichaelM

unread,
Oct 4, 2016, 12:57:14 PM10/4/16
to pforthdev, phil...@mobileer.com
Hi Phil,

That's perfect. Thanks!

Michael
To unsubscribe from this group and stop receiving emails from it, send an email to pforthdev+...@googlegroups.com.

craig.c...@gmail.com

unread,
Jul 15, 2018, 10:36:43 AM7/15/18
to pforthdev
Hi Michael,

Did you ever get this implemented? I am going to work on popen() and pclose() words so that I can shell out to things like curl/wget and others. Was interested in writing some web API clients like slack, whatever.

Cheers,
Craig
Reply all
Reply to author
Forward
0 new messages