3

I am trying to call a batch file from a PowerShell 5.0 Script. The path for the batch file is :

\\192.168.0.1\hde_path\Tools Powershell\abc.cmd

So, my path has a white space inside it and I tried to call it in the following way..

cmd.exe /c "'\\192.168.0.1\hde_path\Tools Powershell\abc.cmd'"

Now, it gives the error:

The system can not find the file specified.

But, please note:

  • This file abc.cmd exists in this location.
  • I have access to this location. Because, I can run this abc.cmd file via command prompt without any issues.

Again, when I am putting abc.cmd file in some path where the path does not have any space in it, e.g. : \192.168.0.1\hde_path\Tools\abc.cmd and I call it using the following command, it runs perfectly fine.

cmd.exe /c '\\192.168.0.1\hde_path\Tools\abc.cmd'

Please help!

5
  • only double quotes should do it cmd.exe /c "\\192.168.0.1\hde_path\Tools\abc.cmd" Commented Feb 24, 2017 at 12:29
  • @JamesC. Thanks for the quick reply. But, I would like to remind you that the path you have used in your comment does not have any space in it. But I need to call a batch file which has a white space in it. Commented Feb 24, 2017 at 12:30
  • @SrijaniGhosh, neither does yours in your last example; anyway, cmd uses " for quotation, ' are just considered normal characters... Commented Feb 24, 2017 at 13:13
  • @aschipfl .. I know my last examples does not contain white spaces. Because, I was writing an example that without white spaces the code is working fine. and with white spaces it is not. Please read the whole question. Thanks for the suggestion though! Commented Feb 24, 2017 at 13:52
  • My comment was still the correct answer, I just copied the wrong path from your question. Commented Feb 24, 2017 at 16:40

2 Answers 2

3

Double quotes works for me

cmd.exe /c "\\127.0.0.1\c$\temp\Test Folder\test.cmd"
Sign up to request clarification or add additional context in comments.

Comments

1

Either

cmd.exe /c '\\192.168.0.1\hde_path\Tools Powershell\abc.cmd'

or

cmd.exe /c "\\192.168.0.1\hde_path\Tools Powershell\abc.cmd"

Should work.

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.