Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Shell calls without stopping the calling programme

Reply
Thread Tools

Shell calls without stopping the calling programme

 
 
Pekka Jarvela
Guest
Posts: n/a
 
      05-04-2004
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
 
Reply With Quote
 
 
 
 
Espen Andersen
Guest
Posts: n/a
 
      05-04-2004
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


"Pekka Jarvela" <> wrote in message
news: om...
> 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



 
Reply With Quote
 
 
 
 
Andy Sinclair
Guest
Posts: n/a
 
      05-04-2004
Pekka Jarvela wrote:
>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);


 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      05-04-2004
Pekka Jarvela wrote:
> 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.
 
Reply With Quote
 
Siemel Naran
Guest
Posts: n/a
 
      05-04-2004
"Pekka Jarvela" <> wrote in message

> 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.


 
Reply With Quote
 
Siemel Naran
Guest
Posts: n/a
 
      05-04-2004
"Andy Sinclair" <> wrote in message

> 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.


 
Reply With Quote
 
Julie
Guest
Posts: n/a
 
      05-04-2004
red floyd wrote:
>
> Pekka Jarvela wrote:
> > 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.


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.
 
Reply With Quote
 
Julie
Guest
Posts: n/a
 
      05-04-2004
Pekka Jarvela wrote:
>
> 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.
 
Reply With Quote
 
Julie
Guest
Posts: n/a
 
      05-05-2004
Julie wrote:
>
> red floyd wrote:
> >
> > Pekka Jarvela wrote:
> > > 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.

>
> 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.
 
Reply With Quote
 
Sten Westerback
Guest
Posts: n/a
 
      05-05-2004

"Siemel Naran" <> wrote in message
news:12Qlc.18380$...
> "Andy Sinclair" <> wrote in message
>
> > 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.


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




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling shell script on Solaris machine from windows without using Telnet ashu.deshpande Java 0 06-24-2008 03:04 AM
Re: How to pass shell variable to shell script from python Gerardo Herzig Python 1 02-27-2008 12:19 PM
Re: How to pass shell variable to shell script from python Christian Heimes Python 0 02-27-2008 10:53 AM
Stopping the cpan shell from fetching the modules list Mumia W. Perl Misc 1 08-10-2006 09:25 AM
can I run unix shell command in the ModelSim shell? clinton__bill@hotmail.com VHDL 2 02-18-2005 10:04 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57