问题
I'm new in using batch scripts, and moderately experienced with octave. I have a lot of data files I examine with octave functions and I am trying to set up so that I can double click on files with a custom extension to directly open octave functions. Think "when I double click on this text file, it opens in notepad."
To do this I've written a very basic .bat file and I've associated my .data files to open using this .bat file. The .bat file looks like this:
C:\Octave\Octave-4.2.1\octave.vbs --no-gui --persist --eval myOctaveFunction.m
pause
I've tested it with a hard coded filename inside "myOctaveFunction." but instead i'd like to actually pass the data file name to myOctaveFunction when I double click on the data file. How do I do this? And, are batch scripts even the right way to do this?
Thanks for your help.
回答1:
Try this batch file, which will echo a few specific items:
@echo off
echo My directory %cd%
echo Batchfile Name %0
echo File to run %1
pause
So %1 parameter will provide you with the filename itself.
You can also use it like this.
@echo off
echo My directory %cd%
echo Batchfile Name %~dpnx0
echo file to run %~dpnx1
pause
So in Short, this should work if you are running this the way I am thinking you do.
C:\Octave\Octave-4.2.1\octave.vbs --no-gui --persist --eval myOctaveFunction('%1')
pause
来源:https://stackoverflow.com/questions/43724855/pass-filename-to-windows-batch-bat-script-when-double-clicking-so-that-it-wil