Board logo

标题: [转载代码] [PowerShell每日技巧]向exe程序传递参数(20140324) [打印本页]

作者: DAIC    时间: 2014-4-3 10:44     标题: [PowerShell每日技巧]向exe程序传递参数(20140324)

Running applications such as robocopy.exe from PowerShell sometimes is not trivial. How do you submit arguments to the EXE so that PowerShell won't change them?

It really is simple: make sure all arguments are strings (so quote the arguments if they are no strings or contain spaces or other special characters). And, make sure you submit one string per argument, not one big string.

This would invoke robocopy.exe from PowerShell and copy all JPG pictures from the Windows folder to another folder c:\jpegs recursively, not retrying on errors, and skipping the folder *winsxs*:
  1. $arguments = "$env:windir\", 'c:\jpegs\','*.jpg', '/R:0', '/S', '/XD', '*winsxs*'
  2. Robocopy.exe $arguments
复制代码
As you can see, the arguments are all strings, and they are submitted as a string array.

That works beautifully for each and every exe file you may ever want to invoke from PowerShell.

http://powershell.com/cs/blogs/tips/archive/2014/03/24/submitting-arguments-to-exe-files.aspx




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2