7 Replies - 196 Views - Last Post: 07 February 2012 - 08:21 AM Rate Topic: -----

Topic Sponsor:

#1 WhiteDog  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 31-January 12

Open simultaneous externals programs with system()

Posted 06 February 2012 - 08:42 PM

Hi, i'm begginner and even finished mey c++ book (starting out with, gaddys). I use code::blocks in Windows 7

Looking forums, I see that:

system("\dir\file.exe");



...opens everything. Ok.

Using what i've learned, I created a program that show a menu with name of programs (one pdf, winamp, code::blocks, jdownloader etc) and I choose that ones that i want open (so, when i start windows, i just open this program and choose them, so will clean my desktop of icons, because I usually open the same files).

I store them in a string. For exemple, the string receives: abef
So, will open listed programs in menu (the 'a', 'b','e' and 'f' programs).

Open the first...but, until I close this file, the second doesnt open :/
Why?

-----------------

Thinking in a solution, this led me to an idea and another doubt and another failed attempt (normal).

Idea:
With the program (begin.exe), i open the first program in the list ('a', usually winamp, with Rush songs), and pass the string with others programs that i want open to other executable (opener.exe) and exits this first program (begin.exe), because was possible open just once program at time with my idea of system().

So, this another program(opener.exe) receives argc and *argv passed from the first program, use the first string in argv to open the next program ('b'), pass the remaining strings to this same second program (opener.exe...yes open it again), but now is with different argc & argv, and exits (the first opener.exe) and on and on...

Like a recursively opens of the same program.

So, how I pass argc and argv to open another executable? By now, i just used argc and argv to open .exe by the terminal.
How I use a navigation in my program, like a terminal command? To see the directories, files and open that one?


-------------
Another failed attempt:

I tried this thing of opening the same file that i'm executing...but doesn't work.
I open one program each time, do open the next file ('b'), call this program that i'm running (to open 'c', now) and exits...but it's not possible...

just open the second called program if i finishes the file that i opened with the system...
seems that system() create a relation with the file opened...

thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Open simultaneous externals programs with system()

#2 jimblumberg  Icon User is online

  • member icon

Reputation: 1892
  • View blog
  • Posts: 5,681
  • Joined: 25-December 09

Re: Open simultaneous externals programs with system()

Posted 06 February 2012 - 09:12 PM

The system() function spawns the new program and waits until that program ends before execution of the current program proceeds. You can not use system() to run multiple programs at once.

Jim

This post has been edited by jimblumberg: 06 February 2012 - 09:13 PM

Was This Post Helpful? 0
  • +
  • -

#3 WhiteDog  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 31-January 12

Re: Open simultaneous externals programs with system()

Posted 06 February 2012 - 09:33 PM

What can I use instead?

thanks
Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is online

  • member icon

Reputation: 1892
  • View blog
  • Posts: 5,681
  • Joined: 25-December 09

Re: Open simultaneous externals programs with system()

Posted 06 February 2012 - 09:53 PM

Why are you trying to use C/C++ to do this? I would suggest using a scripting language of some sort, or maybe put the programs you want to start on start up into your startup folder.

Jim

This post has been edited by jimblumberg: 06 February 2012 - 09:54 PM

Was This Post Helpful? 0
  • +
  • -

#5 #define  Icon User is offline

  • Programmer
  • member icon

Reputation: 565
  • View blog
  • Posts: 2,084
  • Joined: 19-February 09

Re: Open simultaneous externals programs with system()

Posted 06 February 2012 - 09:54 PM

Hi, you can try preceding the program name with the start command.

  system("start notepad");



The program will start a separate window in Windows and return.


Edit: do you not need
system("/dir/file.exe");
// or
system("\\dir\\file.exe");


This post has been edited by #define: 06 February 2012 - 09:59 PM

Was This Post Helpful? 1
  • +
  • -

#6 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1282
  • View blog
  • Posts: 3,659
  • Joined: 04-June 09

Re: Open simultaneous externals programs with system()

Posted 06 February 2012 - 09:55 PM

On Windows, you would use CreateProcess to directly run the program, and not block on them.
Was This Post Helpful? 0
  • +
  • -

#7 WhiteDog  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 31-January 12

Re: Open simultaneous externals programs with system()

Posted 07 February 2012 - 05:07 AM

I trying to do this way because is the only way that I know ;)
...and looking CreateProcess seems that with my knowledge it's no possible do all that I want...

but about calling another program passing argc and argv, it's possible?
Was This Post Helpful? 0
  • +
  • -

#8 GunnerInc  Icon User is online

  • "Hurry up and wait"
  • member icon

Reputation: 314
  • View blog
  • Posts: 901
  • Joined: 28-March 11

Re: Open simultaneous externals programs with system()

Posted 07 February 2012 - 08:21 AM

Going out of your "comfort zone" is how you learn great new things.

Try passing createprocess different parameters and see what happens. Many parameters can be zero/null
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1