Home > Mobile >  Trying to access command line arguments in Visual Studio Code - Python
Trying to access command line arguments in Visual Studio Code - Python

Time:01-19

I am using Visual Studio Code on Windows 10 machine: enter image description here

Here is my code:

import sys

if __name__ == "__main__":

    print(sys.argv[0])
    print(sys.argv[1])

When I execute it, in the terminal window by passing a parameter:

c:; cd 'folder_path\code'; & 'folder_path\python3.9.exe' 'folder_path\.vscode\extensions\ms-python.python-2021.12.1559732655\pythonFiles\lib\python\debugpy\launcher' '58259' '--' 'folder_path\code\cmd_line.py' test  

I get an error

ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

CodePudding user response:

Do you execute the debug command again after you debug the python file? It will not work.

After you debug, the debug server will be closed and the server port will be changed in the next time, so the same debug command can not be executed twice.

You can right-click and select Run Python File in Terminal. And this command can be executed any times.

CodePudding user response:

Try simply run this in the terminal:

python folder_path\code\cmd_line.py test
  •  Tags:  
  • Related