ExternalProcess: questions and comments

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

ExternalProcess: questions and comments

Bill Schwab-2
Bob,

I've been using your ExternalProcess class with some success.  The good news
is that it makes things run, and they seem to work.  The main snag is that
I'm having problems capturing their output.  In the case of LaTeX compiler
drivers, there is a log file that I can grab, which might actually be the
best way to go.  The other executable I want to run is InnoSetup's command
line compiler.  Again, it runs, and with the correct scripts, and the
installers end up where they should (THANKS!!!!!).  However, I'd be very
interested in grabbing all of the compiler output to present to the user,
and ideally parse it for error messages.  I'm using the helper method below,
which is shamelessly stolen from elsewhere in your goodies.  Am I missing
something obvious about the output?

Re #referencesToOtherPackages and friends, could the same effect be obtained
using manual prerequisites?

Have a good one,

Bill



!ExternalProcess class methodsFor!

executeCommand:aStringCommand inDirectory:aDirectoryString
waitForSeconds:anIntegerSeconds
 "Execute a command by launching a separate process."

  | tmpStdinName tmpStdoutName tmpStderrName tmpFile text process startTemps
endTemps diffTemps |

 startTemps := (File find: aDirectoryString, '\_*') collect: [
:aWin32FindData | aWin32FindData fileName ].

 text := ''.

 tmpStdinName := File temporaryFilename.
 tmpStdoutName := File temporaryFilename.
 tmpStderrName := File temporaryFilename.

 process := ExternalProcess new
    commandLine: aStringCommand;
    directory: aDirectoryString;
    secondsToWait: anIntegerSeconds;
    stdinFilename: tmpStdinName;
    stdoutFilename: tmpStdoutName;
    stderrFilename: tmpStderrName;
    yourself.

 [ process executeSync ]
  on: ExternalProcessWaitFailure do: [ :e | text := 'Unable to wait for the
command to complete' ]
  on: ExternalProcessWaitTimeout do: [ :e | text := 'The command issued did
not terminate.  This may ',
         'be because of a problem with the read-only attributes ',
         'on the files involved.' ]
  on: Error do: [ :e | text := 'An ', e class name, ' error occurred, error
text=', e description ].


 "
 tmpFile := FileStream read:tmpStderrName.
 text := text, tmpFile contents.
 tmpFile close."
 ( Array with:tmpStdoutName with:tmpStderrName ) do:[ :fileName |
  tmpFile := FileStream read:tmpStderrName.
  text := text, tmpFile contents.
  tmpFile close.
 ].

 File delete: tmpStdinName.
 File delete: tmpStdoutName.
 File delete: tmpStderrName.

 endTemps := (File find: aDirectoryString, '\_*') collect: [ :aWin32FindData
| aWin32FindData fileName ].
 diffTemps := endTemps difference: startTemps.
 diffTemps do: [ :aFilename | File delete: aFilename ].

 ^text
! !
!ExternalProcess class categoriesFor:
#executeCommand:inDirectory:waitForSeconds:!public! !



--
Wilhelm K. Schwab, Ph.D.
[hidden email]