[英]How do I execute a script from Windows Powershell?
I created a small aws.bat script and then in PowerShell I navigated to the script directory. 我创建了一个小的aws.bat脚本,然后在PowerShell中导航到该脚本目录。
But when I type aws then I get an error message and it does not execute the script. 但是当我键入aws时,我收到一条错误消息,它不执行脚本。 Is there a special thing I should be doing?
我应该做些特别的事情吗?
Here's what I have tried: 这是我尝试过的:
PS C:\G> .\aws.bat
C:\G>$BucketName = "ab-user"
'$BucketName' is not recognized as an internal or external command,
operable program or batch file.
The very first and every othre command has a similar message. 第一个命令和每个其他命令都有类似的消息。
You can't just enter the name on its own, with or without file extension, you first have to tell powershell what to do with it. 您不能只输入名称(带或不带文件扩展名),您首先必须告诉powershell如何使用它。
You can call it as follows: 您可以按以下方式调用它:
& .\aws.bat
If you need the LastExitCode
returned in powershell to check if the bat file worked (0 usually means it worked, anything else usually means it didn't), use Start-Process
as follows: 如果您需要在powershell中返回的
LastExitCode
来检查bat文件是否正常工作(通常0表示正常,否则通常无效),请使用Start-Process
,如下所示:
$batch = Start-Process -FilePath .\aws.bat -Wait -passthru;$batch.ExitCode
And if you want the batch file to be hidden when it is run by powershell do this: 而且,如果要在Powershell运行该批处理文件时将其隐藏,请执行以下操作:
$batch = Start-Process -FilePath .\aws.bat -Wait -passthru -WindowStyle Hidden;$batch.ExitCode
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.