Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 使用powershell启动批处理文件的确切命令_Batch File_Powershell_Parameters - Fatal编程技术网

Batch file 使用powershell启动批处理文件的确切命令

Batch file 使用powershell启动批处理文件的确切命令,batch-file,powershell,parameters,Batch File,Powershell,Parameters,我知道以前有人问过这个问题,我在这里找到了一条线索,它几乎为我提供了我需要的解决方案 以下是链接: 但这只有在我写出完整路径时才有效。例如: $title = "file" $path = "C:\Users\Administrator\Desktop\dcp_bearbeitet\$title\start.bat -p c:\Users\Administrator\Desktop\dcp_bearbeitet\$title\start.prop" c:\Users\Administrator

我知道以前有人问过这个问题,我在这里找到了一条线索,它几乎为我提供了我需要的解决方案

以下是链接:

但这只有在我写出完整路径时才有效。例如:

$title = "file"
$path = "C:\Users\Administrator\Desktop\dcp_bearbeitet\$title\start.bat -p c:\Users\Administrator\Desktop\dcp_bearbeitet\$title\start.prop"
c:\Users\Administrator\Desktop\dcp\u bearbeitet\start.bat-p c:\Users\Administrator\Desktop\dcp\u bearbeitet\start.prop

我想要达到的是一个解决方案,它接受一个带有参数的路径,就像下面这个:

c:\Users\Administrator\Desktop\dcp\u bearbeitet\$title\start.bat-p c:\Users\Administrator\Desktop\dcp\u bearbeitet\$title\start.prop

$title
包含我在本例中使用的文件名。我知道我可以为
-p
命令创建另一个参数,我知道这是可行的,但不幸的是,当我尝试对第一个命令使用相同的方法时,总是会收到错误消息


我希望你们知道解决这个问题的方法。

我认为
调用表达式
在这里可能会有所帮助。 只需按照您希望的方式构建路径,例如:

$title = "file"
$path = "C:\Users\Administrator\Desktop\dcp_bearbeitet\$title\start.bat -p c:\Users\Administrator\Desktop\dcp_bearbeitet\$title\start.prop"
然后调用它:

Invoke-Expression $path

问候保罗

谢谢你,你救了我一天。直到现在我才知道Invoke表达式的作用,这就是为什么我从未尝试过它。我给了你答案。