Running External Process from 4GL on Windows

Posted by Jeff Ledbetter on 17-Jul-2015 17:06

Hi.

Is System.Diagnostics.Process.Start the appropriate .Net alternative for shelling a process?

Does a .Net call have better performance than CreateProcessA or OS-COMMAND?

TIA!

Posted by Matt Gilarde on 18-Jul-2015 11:13

OS-COMMAND SILENT (or OS-COMMAND with no option) launches a shell to execute the command (so, as Simon pointed out, two processes are created) but the shell's console window is hidden. OS-COMMAND NO-CONSOLE launches the process directly without a shell so only one process is created. Both use CreateProcess to do their work. There is a bit of extra overhead using OS-COMMAND NO-CONSOLE as compared to calling CreateProcess directly as an external procedure because OS-COMMAND always checks for the existence of a helper executable even if it's not going to be used. I've made a note to myself to fix that.

I believe that INPUT-OUTPUT THROUGH launches a command shell because it's the most reliable way to redirect stdin and stdout on all versions of Windows.

All Replies

Posted by Matt Gilarde on 18-Jul-2015 07:57

Yes, the Process class is the recommended way to start processes in .NET. Calling CreateProcessA directly is probably slightly faster but the time it takes to actually launch a process will surely swamp whatever slight gains you get from avoiding a .NET call.

Posted by Jeff Ledbetter on 18-Jul-2015 10:04

 
Are both better than OS-COMMAND?
 
Jeff Ledbetter
skype: jeff.ledbetter
 
[collapse]
From: Matt Gilarde [mailto:bounce-mattg@community.progress.com]
Sent: Saturday, July 18, 2015 7:58 AM
To: TU.OE.Development@community.progress.com
Subject: RE: [Technical Users - OE Development] Running External Process from 4GL on Windows
 
Reply by Matt Gilarde

Yes, the Process class is the recommended way to start processes in .NET. Calling CreateProcessA directly is probably slightly faster but the time it takes to actually launch a process will surely swamp whatever slight gains you get from avoiding a .NET call.

Stop receiving emails on this subject.

Flag this post as spam/abuse.

[/collapse]

Posted by Simon L. Prinsloo on 18-Jul-2015 10:46

If you run OS-COMMAND without the SILENT option, as DOS box will open / flash, so I suspect that OS-COMMNAND will launch a shell and then execute the command in the shell, thus it creates a process (cmd.exe), establish an environment, and then launch your process from within that shell.

For that reason I believe that not using OS-COMMAND comes down to directly creating the single process you want as opposed to creating a shell to create the process you need.

But this is a wild guess. Maybe someone can tell us what OS-COMMAND actually does (and why INPUT-THROUGH will always flash a dos box).

Posted by Matt Gilarde on 18-Jul-2015 11:13

OS-COMMAND SILENT (or OS-COMMAND with no option) launches a shell to execute the command (so, as Simon pointed out, two processes are created) but the shell's console window is hidden. OS-COMMAND NO-CONSOLE launches the process directly without a shell so only one process is created. Both use CreateProcess to do their work. There is a bit of extra overhead using OS-COMMAND NO-CONSOLE as compared to calling CreateProcess directly as an external procedure because OS-COMMAND always checks for the existence of a helper executable even if it's not going to be used. I've made a note to myself to fix that.

I believe that INPUT-OUTPUT THROUGH launches a command shell because it's the most reliable way to redirect stdin and stdout on all versions of Windows.

Posted by Simon L. Prinsloo on 18-Jul-2015 16:27

Thanks Matt

Posted by Jeff Ledbetter on 20-Jul-2015 15:35

Thank you for the expert insight Matt!
 
Jeff Ledbetter
skype: jeff.ledbetter
 
[collapse]
From: Matt Gilarde [mailto:bounce-mattg@community.progress.com]
Sent: Saturday, July 18, 2015 11:14 AM
To: TU.OE.Development@community.progress.com
Subject: RE: [Technical Users - OE Development] Running External Process from 4GL on Windows
 
Reply by Matt Gilarde

OS-COMMAND SILENT (or OS-COMMAND with no option) launches a shell to execute the command (so, as Simon pointed out, two processes are created) but the shell's console window is hidden. OS-COMMAND NO-CONSOLE launches the process directly without a shell so only one process is created. Both use CreateProcess to do their work. There is a bit of extra overhead using OS-COMMAND NO-CONSOLE as compared to calling CreateProcess directly as an external procedure because OS-COMMAND always checks for the existence of a helper executable even if it's not going to be used. I've made a note to myself to fix that.

I believe that INPUT-OUTPUT THROUGH launches a command shell because it's the most reliable way to redirect stdin and stdout on all versions of Windows.

Stop receiving emails on this subject.

Flag this post as spam/abuse.

[/collapse]

Posted by OctavioOlguin on 29-Jul-2015 12:27

I think this question IS answered, by the SAME GUY who made the THING himself.. ? (...and thanks for that)

This thread is closed