The console prompt window appears on the system ("start dir"), but not on the system ("start ipconfig")

I am trying to create a simple UI that launches the command prompt in the background (but the Windows console shouldn't disappear) while pressing each button at the same time, respectively.

But first, I'll try something like system("start dir");

to see if the button works.

Here is the problem: when I click on the left button, the Windows console appears and does not exit the block, I close it. But this only works with system("start dir");

. If I change dir to ipconfig (or some other call function) the windows console pops up for a second and exits. I've tried something like system("PAUSE");

or getch();

etc, but it doesn't work.

Why does this command work with dir but not another command?

CodeUI

+3


source to share


1 answer


There is a fundamental difference between DIR and IPCONFIG, the DIR command is built into the command processor (aka shell), IPCONFIG is a separate program stored in c: \ windows \ system32.

When do you enter START /? on the command line, you can see why he treats them differently:

If it is an internal cmd command or a batch file then
the command processor is run with the /K switch to cmd.exe.
This means that the window will remain after the command
has been run.

If it is not an internal cmd command or batch file then
it is a program and will run as either a windowed application
or a console application.

      

An alternative is to ask the shell to execute the command and exit after that. You use the / c option:



  system("cmd.exe /c dir");

      

Or even simpler, since system () automatically transfers the job to the shell:

  system("dir");

      

Just stop using start :)

+2


source







All Articles