system() and no console ?

B

Bugs

I'm very new to C and am having a hard time figuring out how to pass a
command to the underlying OS so as it doesn't keep the console window
open. By double-clicking from Windows Explorer, I want the other
process to just spawn and the console to close.

For example, on Windows XP, I make the following call:

system(my_command);

where my_command = 'my_program.exe'.
But in Windows the console window stays open until my_program.exe exits.
I guess that makes sense but how would I change my_command or is there
an alternative to system() that would spawn a new process and then
immediately return so my application can complete and close the console?
I tried 'my_program.exe &', but that didnt work either.

Thanks!
 
W

Walter Roberson

I'm very new to C and am having a hard time figuring out how to pass a
command to the underlying OS so as it doesn't keep the console window
open. By double-clicking from Windows Explorer, I want the other
process to just spawn and the console to close.

Anything to do with underlying OS's and console windows is outside the
scope of C itself. You should ask the question in a Windows newsgroup.
 
B

Bugs

Walter said:
Anything to do with underlying OS's and console windows is outside the
scope of C itself. You should ask the question in a Windows newsgroup.

My apologies, I'll ask in the Windows newsgroup. I thought the answer
might be an alternative C library call instead of system() ?
Thanks
 
J

Jack Klein

My apologies, I'll ask in the Windows newsgroup. I thought the answer
might be an alternative C library call instead of system() ?
Thanks

Two things.

Try the Windows group it is
excellent and has a good traffic level and response rate.

And there is no alternative standard C library call to system(). This
is the one and only function that allows a C program to possibly
interact with other executables. All others are non-standard,
platform specific extensions. The methods you find for Windows will
not work at all on Linux or a Macintosh.
 
W

Walter Roberson

Walter Roberson wrote:
My apologies, I'll ask in the Windows newsgroup. I thought the answer
might be an alternative C library call instead of system() ?

Sorry, doesn't exist.

If it were Unix then there are techniques involving multiple shell levels
and 'nohup' -- or better yet, POSIX extensions such as setsid()
and O_NOCTTY when opening devices. But those are OS (or at least POSIX)
specific, not part of C, and I have idea what the Windows paradigm would be.
 
B

Bugs

Thanks to everyone who responded.
FYI - I found a workaround:
As I'm passing system() a platform-specific WinXP command, I changed the
command from 'myprogram.exe' to 'start myprogram.exe' and that worked
fine. The console still pops up but for just an instant.
Thanks again.
 
K

Keith Thompson

Bugs said:
Thanks to everyone who responded.
FYI - I found a workaround:
As I'm passing system() a platform-specific WinXP command, I changed
the command from 'myprogram.exe' to 'start myprogram.exe' and that
worked fine. The console still pops up but for just an instant.

<COMPLETELY_OT>
START /?
prints a usage message that you might find illuminating.
</COMPLETELY_OT>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top