I have the following code in my bat file which saved as MyLM.bat:
#echo off
matlab -automation -r "addpath('C:\Users\mojtaba\BrainModel');AddPathes;MyLM('MT5Test_LM')" > matlab_output.log
exit
In which i simply add the main path and then necessary paths and then i run my function (Which is MyLM). I am running the following code from my matlab command prompt :
!start "MATLAB test" /Min /B MyLM.bat
and it works fine and i am happy! So i can run different instances of matlab separately using different bat files. What will makes me happier is that i can pass my argument (which is 'MT5Test_LM') from matlab command prompt. So i dont need to save different bat files. What i actually need is to have some code like this :
!start "MATLAB test" /Min /B MyLM.bat 'MT5Test_LM'
then i need some piece of codes in my bat file to read this argument and concatenate some strings.
Is there any suggestion?
Have you tried using the input argument of the batch file (%1)?
See, e.g., this manual on batch file input argument.
You might want your bathc file to look like
matlab -r "myLM( %1 )"
Related
imagine I have a files with certain extensions (for example '.abc').
The default program I set for files with this special extension is a batch script with powershell commands in it, so when I doubleclick the file, it runs the script. It works.
Now my question is, can I somehow get the file path of the .'abc' file I opened? Is there a command for this?
Thank you.
Inside of your batch file it should be possible to access the ".abc" file via parameter %1.
Per default Windows sends the filename of the file you doubleclick to the receiving program (or batch script) as parameter one.
Try this inside of your batch file (near the top) and pick what suits your needs:
echo param1: %1
echo param1 unquoted: %~1
echo drive: %~d1
echo drive and path: %~dp1
echo filename and extension only: %~nx1
set myparam=%~1
echo myParam: %myparam%
See the help documentation of for for the "%~..." syntax by executing for /? in a cmd.exe command window. (Or read here: What does %~dp0 mean, and how does it work?)
I have a DOS batch-file MYDOS.BAT containing:
My C-application (myApp.exe) reading an input-file (inputFile) from the DOS-command line
myApp.exe analyses inputFile and exits/returns with a code=N
How can I pass value N into my MATLAB script?
E.g: MYDOS.BAT is run by DOS>MYDOS inputFile and contains the following lines:
myApp %1
echo %ERRORLEVEL%
set samplerate=%ERRORLEVEL%
echo %samplerate%
...
C:/... matlab mymatlab.m ...
HOW CAN I THEN PASS the value %samplerate% into my mymatlab.m script?
You can use the system command to use DOS commands in Matlab. Use doc system to see the documentation.
System can have 2 outputs. The first one is a status, which will tell you if the operation succeeded. The second one is the output to the command prompt. You can parse this to get your value. You could use the following code as a guide for your situation:
[status,cmdout]=system('MYDOS.bat');
cmdout will contain the string that you are echoing to the command prompt.
I have created a .sed file for input in iexpress.exe. The entry in .sed file has two applications. One is a batch file and another is an .exe file, for example:
AppLaunched=cmd.exe /c abc.bat
AppLaunched2=setup.exe
After creating the setup and executing, only the batch file is executed. I want to execute both files.
Any idea?
If I understand your problem correctly you could try using & to chain commands,
AppLaunched=cmd.exe /c abc.bat & setup.exe
There are a few other ways but this is one of the most simplistic.
I need to create output files that include the input I'm providing. For example, a run of the program might look like:
Input command: do_things
Things have been done.
Input command: stop_doing_things
Things are no longer being done.
Where "do_things" and "stop_doing_things" are input from the user.
How can I output all of the above to a file using command prompt functions?
It's not clear what environment using "script " command linux will open a new shell and save everything done it to
This works for you, if you run it at last...
CMD > D:\mycmdout.txt
In that case, maybe you can capture your input as a variable. Echo the variable into the >> mycmdout.txt, then procede with the actual commands, again piped into >> mycmdout.txt as Sunny suggested.
SET /P variable=EnterInputHere
echo %variable% >> mycmdout.txt
EDIT: Be sure to use double >> as to append result to file.
I am trying to find a way to register the files with extension .pl as executables.
I spent some time on the web looking for a solution, but I couldn't find anything.
What I can do:
I made a script, let's call it myscript.pl
I can run it like this :
perl myscript.pl [my_script_parameters]
Now since the file is associated with perl, I can also run it as:
myscript.pl [my_script_parameters]
Now, I know that there is somewhere a list of extensions that are considered as executables (.exe, .bat, etc…). I would like to add .pl to this list so that I can run my script like this:
myscript [my_script_parameters]
Does anyone know how to do this?
Yes, there is built-in support for this. If you check the help for command FTYPE you will see a perl example.
C:>help ftype
Displays or modifies file types used
in file extension associations
FTYPE [fileType[=[openCommandString]]]
fileType Specifies the file type to
examine or change openCommandString
Specifies the open command to use when
launching files
of this type.
Type FTYPE without parameters to
display the current file types that
have open command strings defined.
FTYPE is invoked with just a file
type, it displays the current open
command string for that file type.
Specify nothing for the open command
string and the FTYPE command will
delete the open command string for the
file type. Within an open command
string %0 or %1 are substituted with
the file name being launched through
the assocation. %* gets all the
parameters and %2 gets the 1st
parameter, %3 the second, etc. %~n
gets all the remaining parameters
starting with the nth parameter, where
n may be between 2 and 9, inclusive.
For example:
ASSOC .pl=PerlScript
FTYPE PerlScript=perl.exe %1 %*
would allow you to invoke a Perl
script as follows:
script.pl 1 2 3
If you want to eliminate the need to
type the extensions, then do the
following:
set PATHEXT=.pl;%PATHEXT%
and the script could be invoked as
follows:
script 1 2 3
You can simply add ";.PL" to the PATHEXT environment variable. Right-click "My computer" > Properties > Advanced > Environment variables > System variables.
Your best approach would be to write a batch file called myscript.bat, place it in your path, and have it run your script.. e.g.
#echo off
c:\perl\bin\perl.exe c:\scripts\myscript.pl %*