Calling an external program that sets the ERRORLEVEL - how can I read this value in Smalltalk?

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

Calling an external program that sets the ERRORLEVEL - how can I read this value in Smalltalk?

Steven LaFavor
I'm wondering if anyone has successfully done this...

Yes, I do know that I can figure out a different way to pass the value back - write to file, etc...

But this would be simpler if possible.

*Steve*




--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/va-smalltalk/a486ed47-c527-4fb8-8093-450769487a99o%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Calling an external program that sets the ERRORLEVEL - how can I read this value in Smalltalk?

Mariano Martinez Peck-2
Hi Steve,

I think it's key to say how do you call the external program. Is that via FFI/PlatformFunction or via UnixProcess/AbtPrograrStarter/OSProcess kind of thing?

Cheers,

On Tue, Sep 29, 2020 at 1:37 PM Steven LaFavor <[hidden email]> wrote:
I'm wondering if anyone has successfully done this...

Yes, I do know that I can figure out a different way to pass the value back - write to file, etc...

But this would be simpler if possible.

*Steve*




--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/va-smalltalk/a486ed47-c527-4fb8-8093-450769487a99o%40googlegroups.com.


--
Mariano Martinez Peck
Software Engineer, Instantiations Inc.

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/va-smalltalk/CAOUkibFTiQJmLz3kB1JsiTX41CqBfH_igW7iRcjhcDjfHdx0tw%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Calling an external program that sets the ERRORLEVEL - how can I read this value in Smalltalk?

Steven LaFavor

Of course.  How silly of me. This is on Windows.

I am actually in the process of writing this now.  My current attempts involve using OSCall's create process routines (dug from the AbtProgramStarter code and the WbApplication>>execute:  methods.)
Roughly, I am executing the following lines


result := (os := OSCall new)
createProcess: nil
lpszCommandLine: 'Powershell.exe -ExecutionPolicy Bypass -NonInteractive -NoLogo -NoProfile -Command ".\scriptname -Param1 arg1 -Param2 arg2" '
lpsaProcess: Null
lpsaThread: Null
fInheritHandles: false
fdwCreate: NormalPriorityClass
lpvEnvironment: Null
lpszCurDir: nil
lpsiStartInfo: (sInfo := OSStartupinfo new)
lppiProcInfo: (pInfo := OSProcessInformation new).
(Delay forSeconds: 5) wait.
pInfo hProcess closeHandle.
pInfo hThread closeHandle

Executing the powershell command in a command prompt works correctly as I can then access %errorlevel% and the script does set it correctly.  I assume that I need to do something before I close the handles.

I've tried adding cmd.exe /K and /C, but nothing that I have attempted as seemed to work,

Do I need to do something like 'ERRORLEVEL' abtScanEnv?  I could not get that to work either.   and I cannot find anything online or in the docs about how to get the errorlevel back into smalltalk.

*Steve*


On Tuesday, September 29, 2020 at 12:17:23 PM UTC-5, Mariano Martinez Peck wrote:
Hi Steve,

I think it's key to say how do you call the external program. Is that via FFI/PlatformFunction or via UnixProcess/AbtPrograrStarter/OSProcess kind of thing?

Cheers,

-- 
Mariano Martinez Peck
Software Engineer, Instantiations Inc.
Email: <a href="javascript:" target="_blank" gdf-obfuscated-mailto="d3zCF3afBQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">mp...@instantiations.com
Twitter: <a href="https://twitter.com/MartinezPeck" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Ftwitter.com%2FMartinezPeck\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFPV-7Bnc-U6phGEh-VZU0iUtY7vw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Ftwitter.com%2FMartinezPeck\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFPV-7Bnc-U6phGEh-VZU0iUtY7vw&#39;;return true;">https://twitter.com/MartinezPeck
LinkedIn: <a href="https://www.linkedin.com/in/mariano-mart%C3%ADnez-peck/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.linkedin.com%2Fin%2Fmariano-mart%25C3%25ADnez-peck%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGyJTUAWXPstaw4J3OpFUYRyFAqmw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.linkedin.com%2Fin%2Fmariano-mart%25C3%25ADnez-peck%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGyJTUAWXPstaw4J3OpFUYRyFAqmw&#39;;return true;">www.linkedin.com/in/mariano-martinez-peck
Blog: <a href="https://marianopeck.wordpress.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fmarianopeck.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHAOaIsyMIYgmQWdQZRuKRdD6gBfw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fmarianopeck.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHAOaIsyMIYgmQWdQZRuKRdD6gBfw&#39;;return true;">https://marianopeck.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/va-smalltalk/3cc8b6e2-3855-4fb8-b9e3-a8f4b85ee26co%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Calling an external program that sets the ERRORLEVEL - how can I read this value in Smalltalk?

Louis LaBrunda
Hi Steve,

I pulled this code from one of my programs.  I does work but I may have removed some things that referred to other parts of my program and wouldn't work for you.  The key is you have to keep asking windows if the called code is done.  Just ask if you have any questions or something doesn't work.

| startUpInfo processInfo os startedOk |

cmdLine := 'your command goes here'.

startUpInfo := OSStartupinfo new.
startUpInfo
dwFlags: 1; "1 - startf_useshowwindow"
wShowWindow: 0. "0 - do not show window"

processInfo := OSProcessInformation new.
os := OSCall new.
startedOk := os
createProcess: nil
lpszCommandLine: cmdLine
lpsaProcess: 0
lpsaThread: 0
fInheritHandles: false
fdwCreate: 0
lpvEnvironment: 0
lpszCurDir: nil
lpsiStartInfo: startUpInfo
lppiProcInfo: processInfo.

startedOk ifTrue: [
[ | exitCodeBytes exitCode cnt exitCodeMsg |
cnt := 0.
exitCodeBytes := ByteArray new: 4.
[
processInfo hProcess getExitCodeProcess: exitCodeBytes.
exitCode := exitCodeBytes int32At: 0.
(exitCode = StillActive) & (cnt < timeLimit).
] whileTrue: [
processInfo hProcess waitForSingleObject: 1000.
cnt := cnt + 1.
].
(exitCode = StillActive) ifTrue: [processInfo hProcess terminateProcess: 666].

processInfo hProcess getExitCodeProcess: exitCodeBytes.
exitCode := exitCodeBytes int32At: 0.
processInfo hProcess closeHandle.
processInfo hThread closeHandle.
exitCodeMsg := 'Command exit code: %1 %2' bindWith: exitCode printString with: ((exitCode = 666) ifTrue: ['(TimedOut - Stopped)'] ifFalse: ['']).
self logVeryImptTcpRequest: exitCodeMsg with: cmdLineForLog forConnection: commandData.
self logCmdResult: 'CmdLog.txt'.
self logCmdResult: 'ErrLog.txt'.
commandRunning := false.
] forkReadyAt: Processor userBackgroundPriority named: 'RunUserCommand'.


On Tuesday, September 29, 2020 at 1:36:37 PM UTC-4 [hidden email] wrote:

Of course.  How silly of me. This is on Windows.

I am actually in the process of writing this now.  My current attempts involve using OSCall's create process routines (dug from the AbtProgramStarter code and the WbApplication>>execute:  methods.)
Roughly, I am executing the following lines


result := (os := OSCall new)
createProcess: nil
lpszCommandLine: 'Powershell.exe -ExecutionPolicy Bypass -NonInteractive -NoLogo -NoProfile -Command ".\scriptname -Param1 arg1 -Param2 arg2" '
lpsaProcess: Null
lpsaThread: Null
fInheritHandles: false
fdwCreate: NormalPriorityClass
lpvEnvironment: Null
lpszCurDir: nil
lpsiStartInfo: (sInfo := OSStartupinfo new)
lppiProcInfo: (pInfo := OSProcessInformation new).
(Delay forSeconds: 5) wait.
pInfo hProcess closeHandle.
pInfo hThread closeHandle

Executing the powershell command in a command prompt works correctly as I can then access %errorlevel% and the script does set it correctly.  I assume that I need to do something before I close the handles.

I've tried adding cmd.exe /K and /C, but nothing that I have attempted as seemed to work,

Do I need to do something like 'ERRORLEVEL' abtScanEnv?  I could not get that to work either.   and I cannot find anything online or in the docs about how to get the errorlevel back into smalltalk.

*Steve*


On Tuesday, September 29, 2020 at 12:17:23 PM UTC-5, Mariano Martinez Peck wrote:
Hi Steve,

I think it's key to say how do you call the external program. Is that via FFI/PlatformFunction or via UnixProcess/AbtPrograrStarter/OSProcess kind of thing?

Cheers,

-- 
Mariano Martinez Peck
Software Engineer, Instantiations Inc.

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/va-smalltalk/7222631f-180f-4764-9247-b5b03f742168n%40googlegroups.com.