Q3: stdin/stdout?

Bob Arning arning at charm.net
Tue May 23 17:45:27 UTC 2000


On Tue, 23 May 2000 19:20:56 +0200 Stefan Matthias Aust <sma at 3plus4.de> wrote:
>I'm in question mode, so another, perhaps trivial question?  Is there any 
>way to access stdin and stdout on unix Squeaks?
>
>Q3a: As this is another unix specific question: Can I call shell scripts 
>from Squeak and get the script's output (stdout and stderr) as file streams?

Stefan,

This was posted by Ian Piumarta:

10/21/99	Ian Piumarta 	Re:  ?Executing shell command?

Couldn't resist... ;-)

> How can I execute shell command from Squeak

Starting from the squeak 2.6 top-level dir:

	myUnixBox$ mkdir src/System
	myUnixBox$ cd src/System
	myUnixBox$ ln -s ../Makefile .
	myUnixBox$ cat > system.c
	#include <stdlib.h>
	#include "sqVirtualMachine.h"
	
	struct VirtualMachine *interp;
	
	int primitiveSystem(void)
	{
	  int receiver= interp->stackValue(0);
	  int size= interp->stSizeOf(receiver);
	  char buf[1024];
	  int i;
	
	  if ((interp->methodArgumentCount() != 0) ||
	      (interp->fetchClassOf(receiver) != interp->classString()))
	    return interp->success(0);
	
	  for (i= 0; i < size; ++i)
	    buf[i]= ((char *)receiver)[i + 4];
	  buf[i]= '\0';
	
	  system(buf);
	  return 1;
	}
	
	int setInterpreter(struct VirtualMachine *proxy)
	{
	  interp= proxy;
	  return 1;
	}
EOF->	^D
	myUnixBox$ cd ../..
	myUnixBox$ make reconfig
	myUnixBox$ make
	myUnixBox$ cat > String-system.st
	'From Squeak2.6 of 11 October 1999 [latest update: #1559] on 21 October 1999 at 5:48:45 pm'!
	
	!String methodsFor: 'system commands' stamp: 'ikp 10/21/1999 17:48'!
	system		" 'ls' system "
	
		<primitive: 'primitiveSystem' module: 'System'>
		^self primitiveFailed! !
EOF->	^D
	myUnixBox$ ./<myUnixArch>/squeak

When Squeak pops up, open a file list and then file-in
"String-system.st".  Then execute:

	'ls' system

in a workspace somewhere.  If you want to collect the output of the
Unix command, then some variation of the above based on popen(3) is
probably indicated.

Of course, there is probably a much easier way of doing the same thing
using the OSProcess plugin.

A solution that avoids modifying the VM might be to use a Socket to
connect to port 514 on your local machine, and then talk to rshd (but
I guess that's not quite what you had in mind).

Regards,

Ian

(Jeez, work must be boring today. ;-)






More information about the Squeak-dev mailing list