1

I am currently using batch files to run a set of simulations. Each line in the batch file reads:

"filepath\program.exe" "filepath\simulation.file"

The quotation marks exist to bound any spaces that exist within the file paths. Without any spaces in the file paths, the quotation marks can be removed.

When I run the batch file through PowerShell, using the following command, it works fine:

.\batch.bat

The executable is run and the output is written to the host, as if I was running the same batch file in cmd.

However, I want to ditch the batch files and run the command directly through PowerShell. When I run the following, I get the program to execute, though it doesn't run properly and I don't get anything written to host. It also appears to hang until I use Ctrl+C to cancel.

& "filepath\program.exe" "filepath\simulation.file"

Could you please help me with the following?

  • Any resources discussing how PowerShell executes batch files.
  • How to run an executable through PowerShell without using cmd or a batch file and have it write to host.
2
  • Were you to provide the actual paths, names and details somebody may be able to provide a more focused response. Commented Mar 21, 2018 at 9:43
  • Calling a bat file from Powershell is actually using CMD invisibly in the background. PS uses CMD in the background to run the bat file and the output from that is then displayed in the PS Console. If both Start-Process or & don't work correctly, it sounds like your application isn't compatible with PS Console. Commented Mar 21, 2018 at 10:10

2 Answers 2

0

Have you tried Start-Process?

Start-Process -FilePath "filepath\program.exe" -ArgumentList "filepath\simulation.file" -Wait

PS: The Parameter -Wait is optional.

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

2 Comments

Thanks for the suggestion, but it didn't work as I would have liked. When I tried Start-Process it loaded a cmd window (which I would like to avoid) and attempted to run the executable (and was not successful).
As you can read in the help for Start-Process it supports a parameter with the name -NoNewWindow . This would avoid opening a new window.
0

Although I'm not quite sure why yet, I found out that this issue only occurred while working remotely. Whenever I was connected to the network locally the command ran just fine.

Since I plan to execute the command on PCs that are situated locally on the network, I'll leave it at this for now.

Thanks to everyone who commented!

Comments

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.