Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!uflorida!mephisto!cobra!hsu From: hsu@cobra.gatech.edu (Yung-Kao Hsu) Newsgroups: comp.lang.smalltalk Subject: Re: Anyway to run a program directly from smalltalk? Message-ID: <19570@mephisto.UUCP> Date: 22 Feb 90 01:31:51 GMT References: <19566@mephisto.UUCP> <77422@tut.cis.ohio-state.edu> Sender: news@mephisto.UUCP Reply-To: hsu@cobra.UUCP (Yung-Kao Hsu) Distribution: na Organization: ICS, Georgia Tech. Lines: 77 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 |*_|___________________|>