![](/img/trans.png)
[英]Running Python script from .BAT file, taking .BAT Filename as input
[英]Running .bat file from Powershell script with parameters
“部署和映像工具环境”是我使用的快捷方式,它专门运行以下命令-'C:\\ WINDOWS \\ system32 \\ cmd.exe / k“ C:\\ Program Files(x86)\\ Windows Kits \\ 10 \\ Assessment and Deployment Kit \\ Deployment Tools \\ DandISetEnv.bat“'。
我想做的是在Powershell脚本中运行此命令,然后在该新窗口中运行另一个命令。 我需要运行的命令是oscdimg,它无法在powershell中直接运行,此.bat文件需要先运行,然后再运行其中的长oscdimg。 这是我当前的脚本。 最后的所有评论都是我已经采用的不同方法,没有成功。 我得到的最详细的信息是启动.bat文件,但是我认为传递的参数不正确。 谢谢你的帮助
根据请求, 这是我要执行的操作的简单得多的示例。 这个小脚本运行cmd,并尝试添加参数以更改目录,但是最终的cmd窗口不执行该操作。
$srcDIR = Read-Host -Prompt 'Paste the Source Files Directory '
$destDIR = Read-Host -Prompt 'Paste the output destination, with .iso extension '
$etfsbootDIR = "$srcDIR\boot\etfsboot.com"
$efisysDIR = "$srcDIR\efi\microsoft\boot\efisys.bin"
$etfsboot = "`"" + $etfsbootDIR + "`""
$efisys = "`"" + $efisysDIR + "`""
$src = "`"" + $srcDIR + "`""
$dest = "`"" + $destDIR + "`""
$dir8 = "C:\Program Files (x86)\Windows Kits\8.1\Assessment and Deployment Kit\Deployment Tools\amd64\Oscdimg"
$dir10 = "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\amd64\Oscdimg"
if(Test-Path $dir8) {
# cd $dir8
$etftest = $dir8 + "\etfsboot.com"
}
elseif(Test-Path $dir10){
# cd $dir10
$etftest = $dir10 + "\etfsboot.com"
}
else{
"No Assessment and Deployment Kit detected."
return
}
$etft = "`"" + $etftest + "`""
if(Test-Path $etfsbootDIR) { "etfsboot.com found at $etfsboot" }
if(Test-Path $efisysDIR) { "efisys.bin found at $efisys" }
$beginning = "./oscdimg.exe -m -o -u2 -udfver102 -bootdata:2#p0,e,b"
$middle = "#pEF,e,b"
$command = $beginning + $etfsboot + $middle + $efisys + " " + $src + " " + $dest
$rest = "C:\windows\system32\cmd.exe /k 'C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\DandISetEnv.bat'"
$shortcut = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Windows Kits\Windows ADK\Deployment and Imaging Tools Environment.lnk"
# Start-Process -FilePath $shortcut -ArgumentList $command
# cmd.exe /c $rest $command
# cmd %1 $rest
# & $rest $command
我在参数开头缺少/ c或/ k,因此cmd显然可以运行它。 (/ c运行参数并关闭窗口,/ k运行参数并保持窗口打开)
工作示例
$command = "/k cd .."
Start-Process cmd -ArgumentList $command
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.