Pass filename to windows batch (.bat) script when double clicking so that it will run in octave

三世轮回 提交于 2019-12-07 20:18:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!