6

A similar question was asked several times on SO, and usually the answer is one of:

  • run the same command on PowerShell because it's also there
  • run cmd and then the commands
  • invoke cmd passing /c

and a few other things that I've already tried. But my problem is: I have a specific program (cntkpy34.bat) that refuses to run on PowerShell. That is, with any of solutions like above I still get "Please execute this script from inside a regular Windows command prompt."

So what I really want is to invoke a new cmd.exe window and run the commands on it. How can this be achieved in a PowerShell script?

EDIT: inspecting the batch-file, this is how it verifies the shell:

if /I "%CMDCMDLINE%" neq ""%COMSPEC%" " (
    echo.
    echo Please execute this script from inside a regular Windows command prompt.
    echo.
    exit /b 0
)

Even starting a new cmd.exe process won't do it.

3
  • 4
    Then just remove that part, which verifies shell, from cntkpy34.bat file. And if you can not edit that file, then just satisfy that condition with that PowerShell command: $env:CMDCMDLINE=$env:COMSPEC. Commented Nov 12, 2016 at 13:22
  • yeah, i would suggest doing just that ;) Commented Nov 12, 2016 at 13:30
  • @PetSerAl none of those are set on PS (they point to cmd.exe with no args) and I'm not sure that's safe because it has to activate an Anaconda environment. I'll try it anyway. Commented Nov 12, 2016 at 13:39

1 Answer 1

11

Start-Process cmd -Argument "/c cntkpy34.bat" -RedirectStandardOutput somefile

This will open a new cmd window and run that there

Sign up to request clarification or add additional context in comments.

5 Comments

Awesome. Is there a way to capture the output?
Huh, the captured output still shows Please execute this script from inside a regular Windows command prompt.. This is one hard cookie.
this doesn't make sense, this is what is getting executed: C:\>if /I ""C:\Windows\system32\cmd.exe" /c 1.bat " NEQ ""C:\Windows\system32\cmd.exe" "
That didn't solve my problem, but it is the answer to my question so I'll accept it anyway.
well, i'm sorry for that, but you could adjust the original bat file to include your powershell script invocation command, just like PetSerAI said

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.