简体   繁体   English

如何从Windows Powershell执行脚本?

[英]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.

相关问题 如何从 Windows 命令提示符调用提升的 PowerShell 以执行命令和 PowerShell 脚本文件? - How do I call an elevated PowerShell from Windows command prompt to execute commands and a PowerShell script file? 如何从Windows Powershell脚本执行Perl脚本 - How to execute perl script from a Windows Powershell script 如何使用 Windows 任务计划程序自动执行 PowerShell 脚本? - How do I execute a PowerShell script automatically using Windows task scheduler? 从Windows命令提示符执行PowerShell脚本 - Execute a PowerShell script from a Windows command prompt 如何通过快捷键执行 powershell 脚本? - How do I execute a powershell script by a shortcut key? 当记事本不是默认应用程序时,如何从 Windows 资源管理器运行 PowerShell 脚本? - How do I run a PowerShell script from Windows Explorer when Notepad is not the default application? 如何通过 Powershell 脚本在 Windows 终端中创建新的自定义配置文件? - How do I create a new custom profile in Windows Terminal from a Powershell script? 如何编写Powershell脚本在Windows上设置开发人员环境? - How do I write a powershell script to setup a developer environment on Windows? 如何为运行2个python脚本的Windows创建Powershell脚本 - How do I create a powershell script for windows that runs 2 python scripts 如何使用 PowerShell 中的函数从命令行执行? - How do I use Function in PowerShell to execute from Command Line?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM