473,320 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Executing multiple System() commands

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?
Jul 15 '08 #1
9 3260
Paul Policarp wrote:
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().

--
David Wilkinson
Visual C++ MVP
Jul 15 '08 #2
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?

"David Wilkinson" wrote:
>
Paul:

ShellExecute(), ShellExecuteEx().

--
David Wilkinson
Visual C++ MVP
Jul 15 '08 #3
Paul Policarp wrote:
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.

--
David Wilkinson
Visual C++ MVP
Jul 15 '08 #4
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.

"David Wilkinson" wrote:
>
Paul:

Well, I'm not quite sure what you mean, but you could make these system() calls
from worker threads in your application.

--
David Wilkinson
Visual C++ MVP
Jul 16 '08 #5
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.

--
SvenC

Jul 16 '08 #6
"Paul Policarp" <Pa**********@discussions.microsoft.comwrote in message
news:6F**********************************@microsof t.com...
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
Jul 16 '08 #7
Pavel A. wrote:
"Paul Policarp" <Pa**********@discussions.microsoft.comwrote in
message news:6F**********************************@microsof t.com...
>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")
'start' is a cmd.exe built-in, not a command, so you can't use it with the
system() function.
>
Regards,
--PA

Jul 16 '08 #8
no of course but you can do (if you are lazy) :

system ("cmd /c start foo")

/LM

"Ben Voigt [C++ MVP]" <rb*@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Pavel A. wrote:
>"Paul Policarp" <Pa**********@discussions.microsoft.comwrote in
message news:6F**********************************@microsof t.com...
>>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")

'start' is a cmd.exe built-in, not a command, so you can't use it with the
system() function.
>>
Regards,
--PA


Jul 17 '08 #9
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

"Luc E. Mistiaen" <lu**********@advalvas.be.no.spamwrote in message
news:OJ**************@TK2MSFTNGP06.phx.gbl...
no of course but you can do (if you are lazy) :

system ("cmd /c start foo")

/LM

"Ben Voigt [C++ MVP]" <rb*@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>Pavel A. wrote:
>>"Paul Policarp" <Pa**********@discussions.microsoft.comwrote in
message news:6F**********************************@microsof t.com...
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")

'start' is a cmd.exe built-in, not a command, so you can't use it with
the system() function.
>>>
Regards,
--PA


Jul 17 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Falk Schneider | last post by:
I wrote a PHP shell script under Linux which puts all existing PS-Files within a directory into a list and should then start a single Ghostview window for each file. Sounds simple, but it's not: ...
2
by: Simon Hawkins | last post by:
I seem to remember there's a java function for executing commands on the native system (UNIX in this case) but cannot remember which. Anyone know? Also, is it possible to grab the results of the...
6
by: twsnnva | last post by:
Could anyone give me an example (code) of a simple program with a button that when clicked executes a linux shell or windows dos command like "ifconfig" or "ipconfig" and prints the output...
2
by: Marcos | last post by:
Hi guys, I realise this question has been answered in one form or another many times before but I can't quite find the solution I need. I am trying to run multiple subprocesses from a python...
2
by: Tony Liu | last post by:
Hi, I want to get the name of the calling function of an executing function, I use the StackTrace class to do this and it seems working. However, does anyone think that there any side effect...
4
by: Justine | last post by:
Hi All, How can v execute DOS command while executing Console Application written using C#, like cls,dir commnads. Thanz in Advance, Justine
2
by: Pratibha | last post by:
Hi, I want to execute commands through .NET. Using process, i can execute them in WindowsApplication but the process doesn't work in WebApplication. I am executing a batch file which contains...
2
by: Pascal Polleunus | last post by:
(another try with a different subject as it doesn't seem to work with "EXECUTE + transaction = unexpected error -8" :-/) Hi, It seems that there is a problem when executing a dynamic...
3
by: andersond | last post by:
I have a website application that provides online quotes for insurance. I want the application to send an email to the agent when they have requested binding AND execute a branch to the next CGI...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.