开发者

Pass parameter to BAT file and run by double click

开发者 https://www.devze.com 2023-04-03 22:09 出处:网络
I want to pass two file path (for windows) to the script as command line parameters. In windows if we right-click on a file we can see Properties开发者_开发问答 option and there under General tab the

I want to pass two file path (for windows) to the script as command line parameters. In windows if we right-click on a file we can see Properties开发者_开发问答 option and there under General tab the file name like test.bat is displayed. Can we pass parameter from there?

Actually what I want is to pass two parameters as said before and catch those from the script, operate accordingly. The bat file should be executed by double clicking. Is it possible? I searched Google but found nothing (may be I don't know proper search query for this).


You can't do it directly: you need to create a Windows shortcut (right-click on the file in Explorer, select Create Shortcut), and then you can edit the shortcut's Target field to pass it the parameters.


You create a shortcut to the bat script and then go to the properties view of the shortcut. In the Target field, add the parameters after the target path with a space in between.


You create a shortcut to the bat script and then go to the properties view of the shortcut and add the parameters. Or make a bat script that calls the origin bat script with parameters.


Beware of file paths with blanks inside. Use quotes for the path names and %~1 resp. %~2 to remove the quotes inside the batch file.


For the previous answers to work, you need to create several shortcuts for every pair of parameter names you want, so the "parameter" concept becomes useless because you may hard code the two names directly in several copies of the BAT file. The right way to do that is drag the two desired names and drop them in the BAT file.

0

精彩评论

暂无评论...
验证码 换一张
取 消