0

Background

I am attempting to create an interpreter for a toy programming language. I built the interpreter with ANTLR4 + Python. Then, I compiled the interpreter using Nuitka and bundled it using Inno Setup. After installing with Inno Setup, the executable can be invoked in two ways:

  1. Invoking the name from the terminal. (Running mylang myfile.code)
  2. Double-click an associated file. (Clicking myfile.code in the explorer)

Issue

When I run the executable by clicking the associated file, a terminal is spawned, but then it immediately disappears when the myfile.code program finishes, giving me no time to read the output. I found this SO question which lead me to os.system("pause"). However, when this makes my program pause when it is invoked from the terminal normally, which is unnecessary and unwanted.

Question

Is there a way to detect which way the program was invoked so I can pause only when it was run from clicking an associated file?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
SimonUnderwood
  • 469
  • 3
  • 12

1 Answers1

0

You are asking a wrong question. For example, what if you run mylang myfile.code from Win+R window? You won't see the output either. On the other hand, what if your code is started from console just by typing myfile.code? Then you will be pausing for no reason.


What you actually want to check is if your code inherited console from another process (like cmd) – meaning that if your code closes, the console window stays open. Or if new console was created implicitly for your code and it will go away with your process.

See How to check if the program is run from a console?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992