简体   繁体   English

从Windows命令行运行带有参数的python可执行文件

[英]running python executable from windows command line with arguments

I am using the windows7 command prompt and have opened the python interpreter and changed to the directory where the file is located. 我正在使用Windows7命令提示符,并已打开python解释器并更改为文件所在的目录。 The instructions I have say to get into the directory and type 我说的要进入目录并输入的说明

./keyboardControl.py 192.168.1.108

where keyboardControl.py is the name of the file and the ip address is for a robot. 其中keyboardControl.py是文件名,而IP地址是用于机械手的。

I get the error: 我得到错误:

File "", line 1 .\\keyboardControl.py 192.168.1.108 SyntaxError: invalid syntax (with the carrot under the . before ) 文件“”,第1行。\\ keyboardControl.py 192.168.1.108 SyntaxError:语法无效 (胡萝卜放在。之前)

I have also tried: 我也尝试过:

python keyboardControl.py 192.168.1.108

I get the same error with the carrot now under the l in Control. 我现在在Control中的l下遇到与胡萝卜相同的错误。

Any help would be greatly appreciated. 任何帮助将不胜感激。

It sounds like you've launched the Python interpreter and are typing these commands into the REPL. 听起来您已经启动了Python解释器,并在REPL中键入了这些命令。 This is not what you should be doing. 这不是您应该做的。 The commands should be run directly at the cmd prompt, eg: 这些命令应直接在cmd提示符下运行,例如:

C:\Users\me>keyboardControl.py 192.168.1.108

If that does not work (file associations might not be set correctly - Windows does not handle the #! "shebang") the form would be. 如果这样不起作用(文件关联可能设置不正确-Windows无法处理#! “ shebang”),则格式应为。

C:\Users\me>python keyboardControl.py 192.168.1.108

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM