mr_evans2u
mr_evans2u

Reputation: 149

Error when running cmd from powershell script

My script is moving files from one directory to another, once it is done moving the files it then launches a program. I can launch the program from the short cut, I can launch it from .cmd, but when I have Powershell run it I get an error.
"The following error occured initializing the program:
Error accessing file: Conf/logging.properties
The program will now exit."

I only get this error from Powershell.

I've tried the following but none have worked.

 & C:\SMT\App\SMT.exe
 & C:\SMT\App\SMT_Start.cmd
 start-process "cmd.exe" "/c C:\SMT\App\SMT_Start.cmd"

the cmd file works when double clicked, looks like:

 start C:\SMT\App\SMT.exe -clean

The short cut properties look like:
Target: C:\SMT\App\SMT.exe -clean
Start in: C:\SMT\App
Any ideas?

Upvotes: 1

Views: 351

Answers (1)

Matt
Matt

Reputation: 46730

You could have this as a complete PowerShell solution. I think that -WorkingDirectory is what you need.

Start-Process -FilePath "C:\SMT\App\SMT.exe" -WorkingDirectory "C:\SMT\App" -ArgumentList "-clean" -Wait

You can use the -WorkingDirectory to ensure the "Start In:" and -ArgugmentList for the parameter -clean that you are passing. -Wait to not continue processing until the command is complete. This depends if the exe closes on its own or not. Experiment with the presence of that switch.

Upvotes: 1

Related Questions