LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-26-2009, 05:17 PM   #1
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,561

Rep: Reputation: 57
gcc: run several programs in background at same time with system or whatever exec ?


First I compile with this:
Code:
gcc start.c -o start
then second:
my code but still not working?
I would like 3 notepad to be opened at same time ...

Code:
#include <stdlib.h>
#include<stdio.h>

int main()
{
(void)system("notepad.exe");
return(0);
(void)system("notepad.exe");
return(0);
(void)system("notepad.exe");
return(0);
}
Result: Only a single Notepad appears



In any case, someone knows, how can I pass a parameter to my start.exe ?
Quote:
#include <stdlib.h>
#include<stdio.h>

int main()
{
execlp("notepad.exe $1", 1);
execlp("notepad.exe $1", 1);
execlp("notepad.exe $1 ", 1);
}
not workiding either

Last edited by frenchn00b; 04-26-2009 at 05:23 PM.
 
Old 04-26-2009, 05:29 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
The system() function waits until the program (notepad.exe in this case) exits. Then your program continues.

On Linux, a quick&dirty way to fix this is to put an apersand (&) at the end of the command line: system("notepad.exe&");.

Or use fork() and one of the exec system calls (execlp() being the easiest probably).

But I think both of these ways will not work on windows(tm). I don't know how it should be done there.
 
Old 04-26-2009, 05:35 PM   #3
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,561

Original Poster
Rep: Reputation: 57
Quote:
Originally Posted by Hko View Post
The system() function waits until the program (notepad.exe in this case) exits. Then your program continues.

On Linux, a quick&dirty way to fix this is to put an apersand (&) at the end of the command line: system("notepad.exe&");.

Or use fork() and one of the exec system calls (execlp() being the easiest probably).

But I think both of these ways will not work on windows(tm). I don't know how it should be done there.
thank you anyhow

And also I get several CMD boxes open if I run several START.EXE. it is full in my taskbar Cant I hide them somehow?
http://www.skyuser.co.uk/images/tutorials/cmd/cmd1.gif

And for winword, is there a way to call another program into the already running winword? not starting another one?

Is there a jedi master of GCC somewhere here ?

thanks a lot!
 
Old 04-26-2009, 06:26 PM   #4
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
You want one of the _spawn family of functions
http://msdn.microsoft.com/en-us/libr...d2(VS.80).aspx
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
system memory size shrinking even without running programs at background parv Linux - General 6 12-26-2007 03:07 PM
PHP: can't exec some programs when run through apache. why? BrianK Programming 3 09-20-2007 04:10 PM
C++: Way to have System run in background? dive Programming 3 08-17-2006 07:29 PM
How to create a run-time executable from another exec + inputs? R00ts Linux - General 3 02-18-2006 04:52 PM
Run programs in background... Cybers19 Linux - Newbie 1 06-02-2004 03:54 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration