Executing multiple System() commands

  • Thread starter Thread starter Paul Policarp
  • Start date Start date
P

Paul Policarp

I'm attempting to make an application that will call and execute multiple
"system()" cmd commands simultaneously. The problem is that when the program
hits the first system() it waits for it to finish executing (and it can run
indefinitely until dismissed with Ctrl+C) and only after it has closed does
it move on to the next.

Is there any way to make the program move on immediately after calling
system(), without waiting for a return value?
 
Paul said:
I'm attempting to make an application that will call and execute multiple
"system()" cmd commands simultaneously. The problem is that when the program
hits the first system() it waits for it to finish executing (and it can run
indefinitely until dismissed with Ctrl+C) and only after it has closed does
it move on to the next.

Is there any way to make the program move on immediately after calling
system(), without waiting for a return value?

Paul:

ShellExecute(), ShellExecuteEx().
 
Thank you, but sadly, that doesn't help me a lot. My command is in the form
of a string and it's not a standard Windows command. It's custom made
depending on certain parameters the application sets. Is there any function
that runs commands in a separate process but takes a single string as an
argument?
 
Paul said:
Thank you, but sadly, that doesn't help me a lot. My command is in the form
of a string and it's not a standard Windows command. It's custom made
depending on certain parameters the application sets. Is there any function
that runs commands in a separate process but takes a single string as an
argument?

Paul:

Well, I'm not quite sure what you mean, but you could make these system() calls
from worker threads in your application.
 
I apologize, my phrasing tends to be confusing when I'm in a hurry. Combine
that with not being a native English speaker and there you have it. I'll
attempt to articulate my predicament more accurately.

I am building an application. Based on the state of checkboxes, radio
buttons, edit boxes and IP controls, the application will compose a "command"
string that varies parameter-wise every time the application is run. This
string changes during the execution of the program from the beginning to the
end and a separate process needs to be launched every time the command
changes.

system(command); doesn't do that for me and I haven't been able to make
ShellExecute() do it properly either. I did ponder launching in different
threads but I'm a novice programmer and I'm not good at concurrent
programming.

Is there another solution? All I need is several processes being launched
simultaneously in parallel to my parent program.

Thank you.
 
Hi Paul,
I haven't been able to
make ShellExecute() do it properly either. I did ponder launching in
different threads but I'm a novice programmer and I'm not good at
concurrent programming.

ShellExecute(0, NULL, _T("yourExecuteableWithPath"), _T("your command line
options"), NULL, SW_SHOWNORMAL);

So all you have to do is split up your command line "c:\myProg\prog.exe
hello world" into "c:\myProg\prog.exe" and "hello world"

ShellExecute does not wait for the command to finish so you can spawn as
many commands in parallel as you want or your computer can cope with.
 
Paul Policarp said:
I'm attempting to make an application that will call and execute multiple
"system()" cmd commands simultaneously. The problem is that when the
program
hits the first system() it waits for it to finish executing (and it can
run
indefinitely until dismissed with Ctrl+C) and only after it has closed
does
it move on to the next.

Is there any way to make the program move on immediately after calling
system(), without waiting for a return value?

Maybe what you need is "start" command (see the Windows help about it).
By default it does not wait.

For example, change system("foo.exe") to change system("start foo.exe")

Regards,
--PA
 
Pavel said:
Maybe what you need is "start" command (see the Windows help about
it). By default it does not wait.

For example, change system("foo.exe") to change system("start
foo.exe")

'start' is a cmd.exe built-in, not a command, so you can't use it with the
system() function.
 
Nope, I'm not that lazy :) Quite often actually test thing before posting.
Function system() internally runs the command via cmd.exe (or whatever
%comspec% resolves to).
so system( "start notepad") will work as expected.


Regards,
--PA
 
Back
Top