question

HippopotamusDefence-7970 avatar image
0 Votes"
HippopotamusDefence-7970 asked MotoX80 commented

running a cmd within powershell

I am trying to run a cmd file through powershell. The file is located in a folder inside Program Files.

I have tried

invoke-item -path "c:\program files\myProgram\myfile.cmd" which gave me cmd file not found message.

Then, I tried to put that in variable and pipe it to cmd
$myvariable = "c:\program files\myProgram\myfile.cmd"
$myvariable | cmd

That gave an error "'C:\Program' is not recognized as an internal or external command". Apparently, the space in the string there is a problem.

Next, I tried to cd to "c:\program files\myProgram" and then run cmd /c myfile.cmd. Now that seems to work except the powershell does not stop and has to be manually stopped.

Any suggestions as to how to run that cmd from within powershell script? When run from command prompt (elevated privilege) it works fine.

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MotoX80 avatar image
1 Vote"
MotoX80 answered MotoX80 commented

Just run cmd.exe and put quotes around the cmd file name.

103127-capture.jpg



capture.jpg (45.2 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

this does not work with a space. so does not answer the question. i am having the same problem. also your solution does not allow for a variable either. really could use a working answer to this problem. thanks

0 Votes 0 ·
MotoX80 avatar image MotoX80 johncgilliland ·

this does not work with a space

I can't help you it you don't tell me where the space is or provide some example of the commands you are trying to execute.

so does not answer the question.

Since HippopotamusDefence-7970 asked the question, he will be the judge of whether it was answered or not.

i am having the same problem. also your solution does not allow for a variable either.

The question did not ask for a variable to be used.

really could use a working answer to this problem.

Then ask your own question and share the code you are trying to run. Explain the details of your problem.



0 Votes 0 ·