Running CMD command in PowerShell

前端 未结 5 1139
逝去的感伤
逝去的感伤 2020-12-02 12:02

I am having a bunch of issues with getting a PowerShell command to run. All it is doing is running a command that would be run in a CMD prompt window.

Here is the co

5条回答
  •  抹茶落季
    2020-12-02 12:25

    For those who may need this info:

    I figured out that you can pretty much run a command that's in your PATH from a PS script, and it should work.

    Sometimes you may have to pre-launch this command with cmd.exe /c

    Examples

    Calling git from a PS script

    I had to repackage a git client wrapped in Chocolatey (for those who may not know, it's a kind of app-store for Windows) which massively uses PS scripts.

    I found out that, once git is in the PATH, commands like

    $ca_bundle = git config --get http.sslCAInfo
    

    will store the location of git crt file in $ca_bundle variable.

    Looking for an App

    Another example that is a combination of the present SO post and this SO post is the use of where command

    $java_exe = cmd.exe /c where java
    

    will store the location of java.exe file in $java_exe variable.

提交回复
热议问题