UKNOWN
UKNOWN

Reputation: 61

I want to open new cmd prompt and insert arguments from a cmd prompt

I tried Start cmd to open new cmd prompt but i am not able to give command line arguments in new cmd ..

I tried with following

system("start cmd") >> "system("C:\\Windows\\System32\\ipconfig");

not working

system(start system("C:\\Windows\\System32\\ipconfig")); 

not working

Upvotes: 2

Views: 227

Answers (2)

Serge Ballesta
Serge Ballesta

Reputation: 148910

As said by Dipak D Desai, you can simply use

system("cmd /c start C:\\Windows\\System32\\ipconfig");

But if you do that in a non console application, here is what will happen :

  • Windows will create a new cmd windows
  • it will execute ipconfig in that window
  • it will close the window as soon as the program ipconfig has ended.

If you want the window to stay open after the end of the command, you can use :

system("cmd /c start cmd /k C:\\Windows\\System32\\ipconfig");

The first cmd /c allows to pass the command start that is an internal command. The second cmd /c (or cmd /k) starts a new shell (cmd.exe) but ask it not to close after executing first command, but instead to open a command loop.

In fact, the first cmd /c is not necessary, since it is implied by the system call. So it should be omitted from the command even if is is harmless (thanks to @eryksun for noticing)

Upvotes: 2

Dipak D Desai
Dipak D Desai

Reputation: 877

Launch a separate CMD Windows, you need to call cmd.exe:

system("cmd.exe /c C:\\Windows\\System32\\ipconfig");

Upvotes: 1

Related Questions