Dear Forum,
I’m trying to run an external code with input file from a Xojo GUI and want to show its output file once the run is completed. The code takes several minutes until generating full output file but when I start the code as follows it ends in the middle. Is there any way for Xojo to wait until the external code is completed?
Dim s as new Shell
s.Execute ("/usr/local/v270/src/mcnpx/mcnpx", "i=/Users/leechoonsik/Documents/input o=/Users/leechoonsik/Documents/output")
MsgBox s.Result
Docs say Timeout is only used on Microsoft Windows.
I’m developing this app for both Windows and Mac so if Timeout works at least for Windows half way done. I will test on Windows. Any alternative for Mac? Also what if I cannot predict the run time? Can Xojo check if the process is still running or not?
On macOS it should just wait until its done if you started it that way
At least if you run that in Terminal does it not return to the cmd line until its done ?
If somehow it returns to the cmd line before that then thats the issue and you need to wait in the PID until its completed
see https://ss64.com/osx/wait.html
then you need to do something like this at the cmd line
/usr/local/v270/src/mcnpx/mcnpx i=/Users/leechoonsik/Documents/input o=/Users/leechoonsik/Documents/output & wait $!
I think - its been a while since I had to write a lot of bash scripts
there are other tricks that can be done BUT this one should do what you need
Thanks for the trick, Norman, but it doesn’t work for me.
When I run this in Terminal, everything works fine: it takes a couple of seconds, creating two output files (output and runtpe). The “output” file is supposed to be about 450KB. However, when I run from Xojo Shell execution, the run stops immediately and the output file size is only 90KB. When I open the output file, I can see the code stops in the middle…
Or, use a Mode = 1 shell and loop until theShell.IsRunning is false
[code]Dim theShell As New Shell
theShell.Timeout = -1
theShell.Canonical = True
theShell.Mode = 1
theShell.Execute("/usr/local/v270/src/mcnpx/mcnpx i=/Users/leechoonsik/Documents/input o=/Users/leechoonsik/Documents/output")
Do
theShell.Poll
Loop Until Not theShell.IsRunning
If theShell.Errorcode <> 0 Then
// Handle error
End If[/code]
Also, note that I don’t separate the command and the aruments - pretend that you’re typing in the Terminal/CmdHost shell …