直接在Powershell中测试批处理语句,而无需将调用包装在批处理文件中 [英] test batch statements directly in powershell without wrapping the call in a batch file
本文介绍了直接在Powershell中测试批处理语句,而无需将调用包装在批处理文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个批处理文件,以使用vscode自动执行任务,在那里我将Powershell作为默认Shell.
I am writing a batch file to automate a task using vscode where I get a powershell as my default shell.
行(如果不存在,则为build(md build)
)在powershell中产生错误.
The line if not exist build (md build)
produces errors in powershell.
当我将同一行打包到名为 test.bat
的批处理文件中时,我可以调用 ./test.bat
并获得预期的行为.
When I pack the same line into a batch file called test.bat
I can call ./test.bat
and get the expected behaviour.
有没有一种方法可以直接在Powershell中测试我的批处理语句?
Is there a way to test my batch statements directly in the powershell?
推荐答案
在Powershell中使用 Test-Path
:
In powershell use Test-Path
:
If(!(Test-Path ".\build")){md ".\build"}
或其他方式.
Cmd /c "your statement"
在$ LastExitCode中获取错误代码
Get error code in $LastExitCode
这篇关于直接在Powershell中测试批处理语句,而无需将调用包装在批处理文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文