Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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
String Powershell参数:路径中的字符串_String_Powershell - Fatal编程技术网

String Powershell参数:路径中的字符串

String Powershell参数:路径中的字符串,string,powershell,String,Powershell,我想从Windows命令提示符启动.ps1。我的Powershell脚本有一个路径参数。这是启动.ps1的命令行 powershell集执行策略不受限制-作用域进程;C:\\MyPowerShell.ps1-路径\“C:\\Test for my script\test1.txt” 在MyPowerShell.ps1中,如果我写入主机路径,我会得到:C:\Test。当第一个空格出现时,它会剪切我的字符串。 如何获得完整路径? Thx.选项2: 不要转义路径,而是从传入的内容中删除引号 $

我想从Windows命令提示符启动.ps1。我的Powershell脚本有一个路径参数。这是启动.ps1的命令行
powershell集执行策略不受限制-作用域进程;C:\\MyPowerShell.ps1-路径\“C:\\Test for my script\test1.txt”
在MyPowerShell.ps1中,如果我写入主机路径,我会得到:C:\Test。当第一个空格出现时,它会剪切我的字符串。 如何获得完整路径? Thx.

选项2: 不要转义路径,而是从传入的内容中删除引号

    $path2file = $path2file.replace('"',"").replace("'","")
这将允许任何人在路径周围加引号(一个公认的实践规范),您的应用程序将去掉引号,并将整个路径放在一个变量中。如果路径未被引用,则该行无效

如果实际文件路径中包含引号(单引号或双引号),则会失败。

选项2: 不要转义路径,而是从传入的内容中删除引号

    $path2file = $path2file.replace('"',"").replace("'","")
这将允许任何人在路径周围加引号(一个公认的实践规范),您的应用程序将去掉引号,并将整个路径放在一个变量中。如果路径未被引用,则该行无效


如果实际文件路径中包含一个引号(单引号或双引号),则会失败。

我已将“:
-path”\“C:\\Test for my script\test1.txt”
放在这里,它可以工作。
Thx:)

我已经把“:
-Path”\“C:\\Test for my script\test1.txt”
放在这里,它就可以工作了。
Thx:)

“我想从Windows命令提示符启动.ps1。”为什么?打开PowerShell,然后运行脚本。您不需要Windows命令提示符(cmd.exe)。因为我正在从Jenkins管道启动它。如果您可以启动可执行文件,则不需要cmd.exe。只需使用适当的参数运行PowerShell;e、 g.:
powershell.exe-NoProfile-ExecutionPolicy Unrestricted-File C:\MyPowerShell.ps1-path“C:\test for my script\test1.txt”
。运行
powershell/?
获取有关如何使用其命令行的详细信息。“我想从Windows命令提示符启动.ps1。”为什么?打开PowerShell,然后运行脚本。您不需要Windows命令提示符(cmd.exe)。因为我正在从Jenkins管道启动它。如果您可以启动可执行文件,则不需要cmd.exe。只需使用适当的参数运行PowerShell;e、 g.:
powershell.exe-NoProfile-ExecutionPolicy Unrestricted-File C:\MyPowerShell.ps1-path“C:\test for my script\test1.txt”
。有关如何使用其命令行的详细信息,请运行
powershell/?