简体   繁体   中英

how to call batch files from a PowerShell 5.0 script which has white space in the path?

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, eg : \\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!

双引号适合我

cmd.exe /c "\\127.0.0.1\c$\temp\Test Folder\test.cmd"

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM