Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.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
Url Powershell参数_Url_Powershell_Escaping_Character - Fatal编程技术网

Url Powershell参数

Url Powershell参数,url,powershell,escaping,character,Url,Powershell,Escaping,Character,我是powershell的超级新手。我有一个脚本,希望将URL作为参数传递。url运行一个PHP进程,创建并下载一个PDF文件,然后脚本打印PDF,然后删除PDF。我无法使URL parm正常工作 下面是我的剧本 $w=$args[0] Start $w $Directory = "C:\Users\pslessor\downloads\" Get-ChildItem -path $Directory -recurse -include *.pdf | ForEach-Object {S

我是powershell的超级新手。我有一个脚本,希望将URL作为参数传递。url运行一个PHP进程,创建并下载一个PDF文件,然后脚本打印PDF,然后删除PDF。我无法使URL parm正常工作

下面是我的剧本

$w=$args[0] 

Start $w

$Directory = "C:\Users\pslessor\downloads\"

Get-ChildItem -path $Directory -recurse -include *.pdf | ForEach-Object {Start-Process -FilePath $_.fullname -Verb Print -PassThru | %{sleep 5;$_} | kill }

Remove-Item C:\Users\pslessor\downloads\* -include *.PDF
此脚本由批处理文件PrintPl.bat执行

SET ThisScriptsDirectory=%~dp0
SET PowerShellScriptPath=%ThisScriptsDirectory%PrintPl.ps1
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '%PowerShellScriptPath%' %1";
我正在用testprint.bat进行测试

C:\Wget\PrintPl "https://partners.wayfair.com/print_shipping_docs.php?Print=1&printPackingSlips=1&PackingSlipPOs=CS287851107"
URL在一个字符串中。这个编辑器正在强制在.php处换行

我得到的错误是 字符串的开头是:

At Line:1 Char:25
+ & 'C:\Wget\Printpl.ps1'   <<<< 'https://partners.wayfair.com/print_shipping_docs.php?print;
is missing the terminator: '.
At line:1 Char:85 
+ & 'C:\Wget\PrintPl.psl' 'https://partners.wayfair.com/print_shipping_docs.php
?print; <<<<

    + CategoryInfo      :ParserError: <https://partner...docs.php?print;:
String> [], ParentContainsErrorRecordException
  + FullyqualifiedErrorid : TerminatorExpectedAtEndOfString

'printPackingSlips' is not recognaized as internal or external command,
Operable program or batch file.
'PackingSlipPOs' is not recognized as an internal or external command,
operable program or batch File

之所以会发生这种情况,是因为当您传递参数时,命令解释器会展开您的变量并看到:

PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& 'C:\Wget\PrintPl.ps1' https://partners.wayfair.com/print_shipping_docs.php?    Print=1&printPackingSlips=1&PackingSlipPOs=CS287851107"
因此,它试图执行的命令是C:\Wget\PrintPl.ps1,并且它假定接下来是参数。由于它传递的内容有一个空格,并且没有括在引号或双引号中,因此它假定它是多个参数。它认为:

执行以下脚本:C:\Wget\PrintPl.ps1 有以下论点:

$Args[0]=? $Args[1]=Print=1和printPackingSlips=1和packingtiplopos=CS287851107 要阻止这种情况发生,您还需要将URL括在引号中,因此您的命令应如下所示:

PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '%PowerShellScriptPath%' '%1'"
PowerShell -NoProfile -ExecutionPolicy Bypass -File "%PowerShellScriptPath%" %*
编辑:好的,这对你的案子不起作用。所以我们要稍微改变一下。我建议您使用-File而不是-Command。因此,批处理文件中的Powershell执行行将如下所示:

PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '%PowerShellScriptPath%' '%1'"
PowerShell -NoProfile -ExecutionPolicy Bypass -File "%PowerShellScriptPath%" %*

您应该能够像以前一样运行批处理文件。我很有信心这会对你有用。

事实上,URL只有一行,没有任何空间,因为这个网站的编辑拆分了我的行,不会让我重新组合。我确实用单引号将%1括起来,这确实解决了字符25处的错误,但仍然在字符85处出现错误。正如错误消息告诉您的那样:TerminatorExpectedAtEndOfString。'C:\Wget\PrintPl.psl“”https://partners.wayfair.com/print_shipping_docs.php 你不是要结束这里的引用不,保罗,不是这样。是批处理命令解释器损坏了字符串。看起来是=符号导致了问题。使powershell认为parm在打印时停止,此时它应该是print=1。答案已更新,我认为这应该是一个赢家。现在,当我按照更新后的答案运行它时,我可以让PS至少向我回显正确的URL。