Shell calls without stopping the calling programme

P

Pekka Jarvela

If I put in my C++ (Visual Studio) a shell call

system("notepad file.txt");

which opens a Notepad window with file.txt, there is a problem that
the programme stops as long as Notepad window is open. Is there a way
to make shell calls so that they don't stop the actual programme?

Pekka
 
E

Espen Andersen

Have you tried

system("start notepad file.txt") ?

Haven't got a chance to try it out before posting, byt it's worth the try...

Ylu should also have a closer look at the Win32 API function ShellExecute(),
this is probably a more reliable way of doing what you want.

Espen
 
A

Andy Sinclair

Pekka said:
If I put in my C++ (Visual Studio) a shell call

system("notepad file.txt");

which opens a Notepad window with file.txt, there is a problem that
the programme stops as long as Notepad window is open. Is there a way
to make shell calls so that they don't stop the actual programme?

ShellExecute(hWnd, "open", "file.txt", NULL, NULL, NULL);
 
R

red floyd

Pekka said:
If I put in my C++ (Visual Studio) a shell call

system("notepad file.txt");

which opens a Notepad window with file.txt, there is a problem that
the programme stops as long as Notepad window is open. Is there a way
to make shell calls so that they don't stop the actual programme?

Pekka

try fork() and exec(). Oh, that doesn't work on your Windows system?
Sorry, your post is OT.
 
S

Siemel Naran

Pekka Jarvela said:
If I put in my C++ (Visual Studio) a shell call

system("notepad file.txt");

which opens a Notepad window with file.txt, there is a problem that
the programme stops as long as Notepad window is open. Is there a way
to make shell calls so that they don't stop the actual programme?

This is the limit of standard C++. The behavior of std::system is platform
dependent.

You can try: the spawn and exec functions in process.h, and othe other
variations people in this thread posted. If you want to know more, write to
a Windows or DOS or UNIX newsgroup.
 
S

Siemel Naran

Andy Sinclair said:
ShellExecute(hWnd, "open", "file.txt", NULL, NULL, NULL);

Sorry for the OT for comp.lang.c++, but must the above use notepad.exe?
Seems no as you don't say notepad.exe in that line. On my system .txt files
open with Vi editor.
 
J

Julie

red said:
try fork() and exec(). Oh, that doesn't work on your Windows system?
Sorry, your post is OT.

Sorry Pekka, but the original post is _on_topic_, your response however is
_off_topic_.

system is part of the C++ library, fork and exec are not.
 
J

Julie

Pekka said:
If I put in my C++ (Visual Studio) a shell call

system("notepad file.txt");

which opens a Notepad window with file.txt, there is a problem that
the programme stops as long as Notepad window is open. Is there a way
to make shell calls so that they don't stop the actual programme?

Pekka

The system() call is synchronous, per the standard.

If you wish to have asynchronous behavior, you will either need to change your
command string (you will need to find out the specifics of your command
interpreter on your particular operating system), or use an operating-specific
call.
 
J

Julie

Julie said:
Sorry Pekka, but the original post is _on_topic_, your response however is
_off_topic_.

system is part of the C++ library, fork and exec are not.

That should have been directed to red floyd, not Pekka.
 
S

Sten Westerback

Siemel Naran said:
Sorry for the OT for comp.lang.c++, but must the above use notepad.exe?
Seems no as you don't say notepad.exe in that line. On my system .txt files
open with Vi editor.

Well.. that's the users choice...
But you can also read the documentation to find out that you can...
ShellExecute(hWnd, "open", "notepad.exe", "file.txt", NULL, NULL);

- Sten
 

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

Forum statistics

Threads
474,169
Messages
2,570,916
Members
47,458
Latest member
Chris#

Latest Threads

Top