1

This is not a duplicate. My problem isn't solved by the other thread!

I know that, on a Windows machine, you can achieve this by expanding the %cmdcmdline% environment variable and checking if the path refers to "%SystemRoot%\System32\cmd.exe".

What would be the equivalent for this on a UNIX/LINUX machine? Is there a cross-platform approach? Would _isatty() work? I tried that but it doesn't seem to do what I want it to...

PS: I'm trying to keep the CMD/Shell open and wait for a key ONLY IF the application was called from a shortcut. I don't want to wait for the key if the application was called from inside an open CMD/Shell window...

EDIT 1:

I've created a method

close_on_tty();

which is defined like this:

void close_on_tty() {
    if(!_isatty(_fileno(stdin)) {
        printf("Press any key to exit...");
        getchar();
    }
    return;
}

I put this method before every single exit statement inside my main method. But it still doesn't work for me. Any suggestions? Is this cross platform? Does it work on windows, too? I figured it would, since it is in the MSDN documentation...

armin
  • 353
  • 1
  • 3
  • 8

0 Answers0