[英]Issue with arguments with quotes in Robot Framework
I am trying to run a simple python script which accept one argument and print it. 我正在尝试运行一个简单的python脚本,该脚本接受一个参数并将其打印出来。 I am executing this python script using keyword Run present in Operating System library of Robot Framework .
我正在使用Robot Framework的 操作系统库中的关键字Run执行此python脚本。
I am trying to execute in following two ways: 我试图通过以下两种方式执行:
${rc} ${output}= Run And Return Rc And Output python "C:\\Users\\Administrator\\Desktop\\abc.py" "C:\Program Files (x86)\Common Files"
Output is coming proper in this case : 在这种情况下输出正常:
Documentation:
Runs the given command in the system and returns the RC and output.
Start / End / Elapsed: 20151119 16:01:57.147 / 20151119 16:01:57.179 / 00:00:00.032
16:01:57.147 INFO Running command 'python "C:\Users\Administrator\Desktop\abc.py" "C:Program Files (x86)Common Files" 2>&1'.
16:01:57.179 INFO ${rc} = 0
16:01:57.179 INFO ${output} = C:Program Files (x86)Common Files
However when I try to run in below way, it's giving error : 但是,当我尝试以以下方式运行时,出现错误:
${rc} ${output}= Run And Return Rc And Output "C:\\Python27\\python.exe" "C:\\Users\\Administrator\\Desktop\\abc.py" "C:\Program Files (x86)\Common Files"
Error: 错误:
16:12:44.481 INFO Running command '"C:\Python27\python.exe" "C:\Users\Administrator\Desktop\abc.py" "C:Program Files (x86)Common Files" 2>&1'.
16:12:44.481 INFO ${rc} = 1
16:12:44.481 INFO ${output} = The filename, directory name, or volume label syntax is incorrect.
If I run same thing on command prompt, it works fine. 如果我在命令提示符下运行相同的内容,则效果很好。
C:\Windows>"C:\Python27\python.exe" "C:\Users\Administrator\Desktop\abc.py" "C:Program Files (x86)Common Files"
C:Program Files (x86)Common Files
Just want to know where I am going wrong for second case with Robot Framework? 只想知道第二种情况下我使用机器人框架出错了吗?
RobotFramework is not using a shell to run the command, but rather is passing it verbose to Windows. RobotFramework没有使用外壳程序来运行命令,而是将其详细地传递给Windows。 So it's looking for a filed named literally
"C:\\Python27\\python.exe"
instead of C:\\Python27\\python.exe
. 因此,它正在寻找一个文件名为
"C:\\Python27\\python.exe"
而不是C:\\Python27\\python.exe
。 Note the wrapping quotes, usually those quotes are processed by the shell before invoking the command. 注意包装引号,通常那些引号在调用命令之前由外壳处理。 So, you should change the command to
C:\\\\Python27\\\\python.exe "C:\\\\Users\\\\Administrator\\\\Desktop\\\\abc.py" "C:\\Program Files (x86)\\Common Files"
因此,您应该将命令更改为
C:\\\\Python27\\\\python.exe "C:\\\\Users\\\\Administrator\\\\Desktop\\\\abc.py" "C:\\Program Files (x86)\\Common Files"
To better understand the difference of the shell argument you can try to compare the result of 为了更好地理解shell参数的区别,您可以尝试比较的结果
subprocess.check_call('"C:\Python27\python.exe" "C:\Users\Administrator\Desktop\abc.py" "C:Program Files (x86)Common Files"')
versus 与
subprocess.check_call('"C:\Python27\python.exe" "C:\Users\Administrator\Desktop\abc.py" "C:Program Files (x86)Common Files"', shell=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.