在一行中有一个包含PowerShell代码的工作批处理文件:
powershell -Command "& {$cont = wget http://САЙТ.info/; $cont = $cont.Content; $FilePath = 'contentFronHtml.txt' -f $env:SystemDrive; $cont | Out-File -FilePath $FilePath -Append -Width 200;}"
我想打破PowerShell代码以获得类似的内容:
SET LONG_COMMAND="$cont = wget http://САЙТ.info/;"
"$cont = $cont.Content;"
"$FilePath = 'contentFronHtml.txt' -f $env:SystemDrive;$cont | Out-File -
FilePath; $FilePath -Append -Width 200;"
powershell -Command "& {LONG_COMMAND}"
如何连接PowerShell代码字符串?
答案 0 :(得分:0)
我会将您的PowerShell代码保存为.ps1文件,然后从命令行运行它:
powershell -File "C:\folder\test.ps1"
然后要在多行上打破长命令,请按照以下答案操作: How to enter a multi-line command
这意味着您将PowerShell代码与批处理代码分开,并且批处理文件中不再存在内联PowerShell代码,这些代码很难阅读。
答案 1 :(得分:0)
做这样的事情:
echo>%temp%\file.ps1 SET LONG_COMMAND="$cont = wget http://САЙТ.info/;"
echo>>%temp%\file.ps1 "$cont = $cont.Content;"
echo>>%temp%\file.ps1 "$FilePath = 'contentFronHtml.txt' -f
echo>>%temp%\file.ps1 $env:SystemDrive;$cont ^| Out-File -
echo>>%temp%\file.ps1 FilePath; $FilePath -Append -Width 200;"
echo>>%temp%\file.ps1 powershell -Command "& {LONG_COMMAND}"
powershell %temp%\file.ps1
答案 2 :(得分:0)
这就是我期望做到这一点的方式:
PowerShell -Command "first line up to the end of a command;"^
"next line up to the end of a command;"^
"another line up to the end of a command;"^
"last line"
您也可以尝试这个想法:
Set "MyCmnd=first line up to the end of a command;"
Set "MyCmnd=%MyCmnd% next line up to the end of a command;"
Set "MyCmnd=%MyCmnd% another line up to the end of a command;"
Set "MyCmnd=%MyCmnd% last line"
Echo %MyCmnd%