[英]PowerShell - How to execute BAT (batch) command on specific file? (Concatenate path and command and propagate arguments )
I need to execute in PowerShell 5 some robot (RobotFramework) batch file on specific robot file.我需要在 PowerShell 5 中对特定机器人文件执行一些机器人(RobotFramework)批处理文件。 Simple usage by documentation is: "robot file.robot" which works but in the PowerShell script I am having issues.
文档的简单用法是:“robot file.robot”可以工作,但在 PowerShell 脚本中我遇到了问题。 I defined:
我定义:
$ROBOT_PATH="C:\Program Files\Robot\Scripts"
But when trying to execute:但是在尝试执行时:
$ROBOT_PATH\robot.bat User.robot
Getting an Error: Unexpected token '\robot.bat' in expression or statement.
出现错误:
Unexpected token '\robot.bat' in expression or statement.
If I try: "$ROBOT_PATH\robot.bat" User.robot
or "$ROBOT_PATH\robot.bat" "User.robot"
then getting: Unexpected token '"User.robot"' in expression or statement.
如果我尝试:
"$ROBOT_PATH\robot.bat" User.robot
或"$ROBOT_PATH\robot.bat" "User.robot"
然后得到: token '"User.robot"' in expression or statement.
So how to concatenate Path and Command and propagate Arguments for that command?那么如何连接路径和命令并为该命令传播Arguments呢? Important thing to emphasize is that I should not first do the " cd to PATH" before executing the command.
需要强调的重要一点是,在执行命令之前,我不应该先执行“ cd to PATH”。 If I do the "cd" then it works!
如果我做“cd” ,那么它就可以了!
You need to put the path to a string like this您需要将路径放入这样的字符串
& "${ROBOT_PATH}\robot.bat" User.robot
To re-enable the variable substitution you have to use the curly brackets.要重新启用变量替换,您必须使用大括号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.