[comp.lang.smalltalk] Anyway to run a program directly from smalltalk?

hsu@boa.gatech.edu (Yung-Kao Hsu) (02/21/90)

I do not browse thru this group often thus the question I asked
might quite well be discussed before.

I've been working on implementing an environment which requires
an interaction between smalltalk and prolog (on Sun workstation).
The communication between the two is thru the use of socket which
comes with ParcPlace System with a C program acts as an agent.
However, the establishing of the comunication link between the
process and Socket are extremely slow and very often freezes
the system for about 3 minutes just for it. Furthermore, one have
to always remember to run the agent beforehand.

The problem could be greatly reduced if somehow I could build
an object that could run a "prolog" or any other process directly
by sending a message to it. Has anyone here known of such thing?

----
YUNG-KAO HSU at ICS, Georgia Tech	| FREE   |~~|~~~~~~~~~~~~~~~~~~~|>
bears the responsiblity for this ads.	| RESUME |* |    I need Food.	|>
Question? Contact=> hsu@boa.gatech	| TAKE   |* |    will work!!	|>
This is a Limited Time Offer. Hurry!!	| ONE    |*_|___________________|>

timothy_hansell@oboe.cis.ohio-state.edu (02/21/90)

In article <19566@mephisto.UUCP> hsu@boa.gatech.edu (Yung-Kao Hsu) writes:
>I've been working on implementing an environment which requires
>an interaction between smalltalk and prolog (on Sun workstation).
>The communication between the two is thru the use of socket which
>comes with ParcPlace System with a C program acts as an agent.
>However, the establishing of the comunication link between the
>process and Socket are extremely slow and very often freezes
>the system for about 3 minutes just for it. Furthermore, one have
>to always remember to run the agent beforehand.
>
>The problem could be greatly reduced if somehow I could build
>an object that could run a "prolog" or any other process directly
>by sending a message to it. Has anyone here known of such thing?

If you look at the Terminal object you will see that it is invoking the
c-shell and then passing through commands from the user to the shell. It
is possible to use this same connection that is used by the Terminal to
send command strings directly to the shell. I've seen it done on some
utilities that ParcPlace is working on. This would allow you to start up
your 'agent' from inside smalltalk ( by that I mean have an object actually
send the command not the user ).
	The problem with this approach is that the documentation about
how this works at that level is very slim ( at least in release 2.3. I haven't
seen the docs for 2.5 yet so I don't know what it says )
	Another possibilty, if ParcPlace has added the feature in 2.5
would be to access the unix 'system' call that runs a command. Many of the
unix calls were available in 2.3 but this particular one was either
missing or not documented. But this feature allows you to make unix system
calls directly from smalltalk.
	Yet one more way to solve the problem, would be to create a 
user-primitive that allows you to send unix commands, and then build an object
to be an interface to this user-primitive. There is a great deal of
documentation on user-primitves, and since you write them in 'C' you can 
do anything you do in C with them.

Sorry, I can't offer any direct help. I've been separated from Smalltalk for
over 6 months now ( believe me it's not easy switching back to C ) and I don't
have direct access to either a running Smalltalk or to the documentation.

>
>----
>YUNG-KAO HSU at ICS, Georgia Tech	| FREE   |~~|~~~~~~~~~~~~~~~~~~~|>
>bears the responsiblity for this ads.	| RESUME |* |    I need Food.	|>
>Question? Contact=> hsu@boa.gatech	| TAKE   |* |    will work!!	|>
>This is a Limited Time Offer. Hurry!!	| ONE    |*_|___________________|>

-tim
---
Tim Hansell
hansell@cis.ohio-state.edu
P.O. Box 687 South Charleston, Ohio, 45268

hsu@cobra.gatech.edu (Yung-Kao Hsu) (02/22/90)

In article <77422@tut.cis.ohio-state.edu> Timothy Hansell writes:
>
>In article <19566@mephisto.UUCP> hsu@boa.gatech.edu (Yung-Kao Hsu) writes:
>>...
>>The problem could be greatly reduced if somehow I could build
>>an object that could run a "prolog" or any other process directly
>>by sending a message to it. Has anyone here known of such thing?
>
>If you look at the Terminal object you will see that it is invoking the
>c-shell and then passing through commands from the user to the shell. It
>is possible to use this same connection that is used by the Terminal to
>send command strings directly to the shell. I've seen it done on some
> ...
>---
>Tim Hansell
>hansell@cis.ohio-state.edu
>P.O. Box 687 South Charleston, Ohio, 45268


I did acknowledge such possibility. However I have been hesitated to
take this approach since I don't have enough document and my exprience
a while ago only bring some troubles. But after seeing Tim's reply, I
realized this might be the only way to solve the problem. Sure enough,
couples of hours in examining the behaviors of Terminal using single
steps, I did figure out how to write a method on CShellPort that acts
like unix's `system' call.

The main question was to ensure the synchronization between the caller
and callee since you could send a shell command for execution but it
could return before the command is done. I adopt an ad hoc strategy to
solve this problem by waiting on the return of csh's prompt (thus the
pattern of the prompt needs to be part of the method). However, this
could be avoided if there's no terminal output for command's execution
where a single wait on any response will be enough.

At this moment, the problem seems to be solved and I would like to
Tim very much for his insighted suggestions that leading me to solve
this problem. For anyone who might be interested at my solution, a
brief outline is given below.

--------------
1) For creating a CShell interface:

	Unix _ CShellPort open.
	Unix receiveBuffer.	"for the initial prompt".

2) For `system':

system: commandStringWithCR
| completed |

	completed _ false.
	Unix sendBuffer: commandStringWithCR.  "make sure a CR exists"
	[ completed ]
	whileFalse: [
		Unix receiveBuffer.
		echo _ Unix receivedString.
		( promptPattern match: echo)
		ifTrue: [
			completed _ true ].
		"do anything you want with the response here" ].

where
	* promptPattern: string constant for csh's prompt pattern.
	* the method receivedString obtain the response from csh.
	  This method can be written following the method
	  `displayCharacters' in class Terminal.
	* Don't forget to release the port after the port is no
	  longer needed.

PS: I couldn't quite believe the solution is so simple but suppose
that is exactly what you could get from a programming environment.
------
YUNG-KAO HSU at ICS, Georgia Tech	| FREE   |~~|~~~~~~~~~~~~~~~~~~~|>
bears the responsiblity for this ads.	| RESUME |* |    I need Food.	|>
Question? Contact=> hsu@boa.gatech	| TAKE   |* |    will work!!	|>
This is a Limited Time Offer. Hurry!!	| ONE    |*_|___________________|>

schang@netcom.UUCP (Sehyo Chang) (02/23/90)

In article <19566@mephisto.UUCP> hsu@boa.gatech.edu (Yung-Kao Hsu) writes:
>
>I do not browse thru this group often thus the question I asked
>might quite well be discussed before.
>
>I've been working on implementing an environment which requires
>an interaction between smalltalk and prolog (on Sun workstation).
>The communication between the two is thru the use of socket which
>comes with ParcPlace System with a C program acts as an agent.
>However, the establishing of the comunication link between the
>process and Socket are extremely slow and very often freezes
>the system for about 3 minutes just for it. Furthermore, one have
>to always remember to run the agent beforehand.
>
>The problem could be greatly reduced if somehow I could build
>an object that could run a "prolog" or any other process directly
>by sending a message to it. Has anyone here known of such thing?
>
>----
Thre are 3 possible solution to this problem:
(1) write class called 'prolog' or something that will manage all i/o
interface to the rest of smalltalk.  It will use 'execv' call to automatically
invoke prolog agent if necessary.
(2) write prolog in smalltalk which is not too big of deal unless you intent
to large amount of inferencing or need to talk to prolog machine
(3) if you have source code prolog(such as C-prolog), you might "embedded"
prolog with smalltalk virtual machine(this is only for ParcPlace smalltalk).

Also, unix socket mechanism is very efficent and shouldn't take 3 minutes,
unless you are doing some kind of synchrous communication. You might want
to fork off prolog-communication as lower prority process and try to do
asynchrous communication much as possible which might yield better performance

-- 
Sehyo Chang						schang@netcom.uucp
Ascent Logic Corp.
(408)943-0630

hsu@python.gatech.edu (Yung-Kao Hsu) (02/23/90)

In article <7709@netcom.UUCP> schang@netcom.UUCP (Sehyo Chang) writes:
>In article <19566@mephisto.UUCP> hsu@boa.gatech.edu (Yung-Kao Hsu) writes:
*>
*>The problem could be greatly reduced if somehow I could build
*>an object that could run a "prolog" or any other process directly
*>by sending a message to it. Has anyone here known of such thing?
*>
*>----
>Thre are 3 possible solution to this problem:
>(1) write class called 'prolog' or something that will manage all i/o
>interface to the rest of smalltalk.  It will use 'execv' call to automatically
>invoke prolog agent if necessary.

Even though the problem was solved following Tim's suggestion, but
your suggestion here sounds interesting. What is the basis for writing
this `prolog' class and where does this method `execv' come from?

>Also, unix socket mechanism is very efficent and shouldn't take 3 minutes,
>unless you are doing some kind of synchrous communication. You might want
>to fork off prolog-communication as lower prority process and try to do
>asynchrous communication much as possible which might yield better performance

The slow response probably has something to do with Georgia Tech's
recent upgrade of systems than socket's own performance. I had used
socket interfacing a yacc program before I wrote my own parser and
the response was reasonable even with synchronizations. However, the
use of CShellPort is better than socket IMO.


>Sehyo Chang						schang@netcom.uucp

---

YUNG-KAO HSU at ICS, Georgia Tech	| FREE   |~~|~~~~~~~~~~~~~~~~~~~|>
bears the responsiblity for this ads.	| RESUME |* |    I need Food.	|>
Question? Contact=> hsu@boa.gatech	| TAKE   |* |    will work!!	|>
This is a Limited Time Offer. Hurry!!	| ONE    |*_|___________________|>