6

I want to do two steps in my c++ program using system().

  1. open the folder system("cd /d ...")
  2. run another program.exe

However, it seems like when I run step2, the folder opened in step1 is already closed. What can I do to make sure that the folder won't be closed, so that I can use another cmd call to run .exe?

Thanks!

user4029119
  • 145
  • 1
  • 4
  • 10
  • Hi, you're going to need to expand on this a little and show us some of the code that you've written to solve your problem. Have a read of [this](http://stackoverflow.com/help/mcve) to give you an indication of what to copy-paste – Yann Oct 16 '14 at 09:40
  • The `cd` command used in the `system()` call will change the directory only for the sub shell opened, not for your actual process. – πάντα ῥεῖ Oct 16 '14 at 09:41
  • You need to put both steps in one `system()` command and how that is done will be platform dependant. – Galik Oct 16 '14 at 09:42

1 Answers1

8

you can use

system("command1; command2; command3");

or

system("command1 && command2 && command3");

Refer To The following link: Using a Single system() Call to Execute Multiple Commands in C

Community
  • 1
  • 1
OshoParth
  • 1,492
  • 2
  • 20
  • 44