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. |
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:
Mariano Martinez Peck Software Engineer, Instantiations Inc. Email: [hidden email] Twitter: https://twitter.com/MartinezPeck Blog: 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/CAOUkibFTiQJmLz3kB1JsiTX41CqBfH_igW7iRcjhcDjfHdx0tw%40mail.gmail.com. |
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:
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. |
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:
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. |
Free forum by Nabble | Edit this page |