Calling unix shell from SP-Forth

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Calling unix shell from SP-Forth

Eduardo Costa
In a previous article, I asked how to call system services from SP-Forth. Of course, it is easy to call libc and other dynamic libraries from SP-Forth.

~/frt/fpForth$ rlwrap ./spf.nux
SP-FORTH - ANS FORTH 94 for Linux
Open source project at http://spf.sf.net
Russian FIG at http://www.forth.org.ru ; Started by A.Cherezov
Version 4.20 Build 001 at 24.Feb.2013

(( S" ls *.f" )) system DROP
ansi-block.f  fsm.f        martinBrad.f  sbnf.f      xconsole.f
bernd.f       gram.f        mbrad.f       sexp.f      xeca.f
brad.f          grammar.f        mulmat.f      strings.f   zeca.f
 Ok

However, if I call cd (change directory), SP-Forth seems to ignore my command.

(( S" cd $HOME" )) system DROP
 Ok
(( S" pwd" )) system DROP
/home/rosa/frt/fpForth
 Ok

As you can see, the command S" cd $HOME" was ignored. I believe that system creates a new shell, changes the directory in the new shell, and reverts to the old shell when control is returned to SP-Forth. My question is: How to inhibit this behavior? Since I want to create a shell language piggybacked on SP-Forth, I need a persistent cd command.



------------------------------------------------------------------------------
Own the Future-Intel(R) Level Up Game Demo Contest 2013
Rise to greatness in Intel's independent game demo contest. Compete
for recognition, cash, and the chance to get your game on Steam.
$5K grand prize plus 10 genre and skill prizes. Submit your demo
by 6/6/13. http://altfarm.mediaplex.com/ad/ck/12124-176961-30367-2
_______________________________________________
Spf-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spf-dev
Reply | Threaded
Open this post in threaded view
|

Re: Calling unix shell from SP-Forth

ygrek-3
On Fri, 29 Mar 2013 16:12:50 -0700 (PDT)
Eduardo Costa <[hidden email]> wrote:

> (( S" cd $HOME" )) system DROP
>  Ok
> (( S" pwd" )) system DROP
> /home/rosa/frt/fpForth
>  Ok

Use the corresponding libc functions directly :

(( S" /etc/" )) chdir .  
0  Ok
(( )) get_current_dir_name ASCIIZ> TYPE
/etc Ok

--
 ~ygrek

------------------------------------------------------------------------------
Own the Future-Intel(R) Level Up Game Demo Contest 2013
Rise to greatness in Intel's independent game demo contest. Compete
for recognition, cash, and the chance to get your game on Steam.
$5K grand prize plus 10 genre and skill prizes. Submit your demo
by 6/6/13. http://altfarm.mediaplex.com/ad/ck/12124-176961-30367-2
_______________________________________________
Spf-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spf-dev