I want to Launch and .exe file from an m-file in MATLAB. The .exe does not Launch when i try. In restPath, the path of the .exe included. I am coding in a Windows Environment using the command line. My idea was to pass the command to run the .exe to the command line.
command = restPath;
[status,cmdout] = system(command,'-echo');
The error message is; Error file .cfg not found...
Do you have any suggestions?
Best regards
Edit: The .exe is now launched in 2 iterations. 1. cd to file, 2. Launch
addpath(restPath);
command = horzcat('cd ',restPath);
[status,cmdout] = dos(command,'-echo');
execute = 'abc.exe';
[statusExe,cmdoutExe] = system(execute,'-echo');
The main issue that I see here is that you are using two separate commands for the cd and the execution. Once the cd command executes, the command line context is thrown away and you start with a new one when you execute the system command (so the cd has no effect).
I would suggest either concatenating the two commands into one using the '&' notation like the following:
[status,cmdout] = dos([command ' & ' execute],'-echo');
or you could change your Matlab workspace first using a standard cd command in your mscript and then execute the system command.
currentPath = pwd;
cd(restPath);
execute = 'abc.exe';
[statusExe,cmdoutExe] = system(execute,'-echo');
cd(currentPath);
It is also possible that the exe you are calling is expecting an additional input to point to the .cfg file (although this may not be an issue if you have that in the same directory as the exe and it expects it to be there).
Related
I need to run a program (a python script made into an exe) on start up, without the console showing up.
In some question, I found the solution, i.e to execute the program. Right now, I'm testing it out with a simple python program filewriter.py that does -
while count != 1000:
f = open('test.txt','a+')
f.write(str(count))
f.close()
sleep 1
The bat file tool.bat :
#ECHO OFF
python "<absolute_path_here>\filewriter.py"
EXIT /B
The VBS file :
Set WinScriptHost = CreateObject("WScript.Shell")
WinScriptHost.Run Chr(34) & "<absolute_path_here>\tool.bat" & Chr(34), 0
Set WinScriptHost = Nothing
If I execute the VBS file (double-click it), everything works fine. The output file appears, without the console appearing. So I added it to registry under
HKCU\Software\Microsoft\CurrenVersion\Run
as WScript "path_to_the_vbs_file".
On Startup, the VBS file executes properly (verified it by adding a MsgBox which displayed the popup) but the call to the bat file is not being executed. How do I make this work?
In windows there are two python executables: python.exe, pythonw.exe. If you don't wish to see the terminal window you must use pythonw.exe.
I need to run a program (a python script made into an exe).
If you covert your script to .exe with help of py2exe it is simillar. You can assing your script to console or windows. Look to Py2exe Tutorial, the console variable can be replace forwindows.
You don't need to create EXE files from python. You can run pythonw.exe with path as argument to your script. Why do you need to create .bat which you run from vbscript ? Look here: Run on windows startup CMD with arguments
I forgot to say, that the Windows Python installer normally create following file association, so the script can run directly.
'.py' to python.exe
'.pyw' to pythonw.exe
Other way how you can run the the script on boot is to use Windows Scheduler. The big advantage is you can setup user rights or more events when start the script. You can run the script manually too and you will last status.
Create Python .exe is sometimes tricky. If you don't need to distribute your script to multiple computers I prefer don't use.
I have an exe written in cpp, which I would like to execute in a sandbox called Sandboxie.
The exe file is requesting for input (using cin command in cpp), the only way I found passing parameters not within argv but for cin is with echo command.
the output of the exe file will go to txt file.
basically, if my program asks for one input, the run command looks like this :
start "D:\Program Files\Sandboxie\start.exe" /B (echo 3) | exetorun.exe > result.txt
The problem I found here is that it just doesn`t work,
so the solution I found is taking the part of parameters pass and exe name to run and inserting it into a batch file (.bat) and running it from the sandbox.
like that :
start "D:\Program Files\Sandboxie\start.exe" /B "runExec.bat"
and runExec.bat will have :
( echo 3 ) | exetorun.exe > output.txt
The problem now is that I have the basic version of Sandboxie which does not let you define a folder for example that no matter what when you try to run a file from there - it will run it from the sandbox... so basically all my points of sandbox is ruined.
Moreover, the idea of making a batch file for that is pretty stupid I think...
The only solution I find that will be the pretties is finding a way to just run the command of executing the wanted file and passing the wanted paramter to it within the first command instead of creating a batch file that will execute those commands.
Does someone know a way in any aspect (another sandbox, how to run the command not from a batch file) that can solve this ?
Thanks !
I've got a .js file that's meant to be executed by Node.js on the command-line. I've got everything set up with npm and such to put the file into the user's path as a "bin". My problem is, because the file ends in .js, running it from the command line is shipping it off to the JScript-based Windows Script Host, instead of node, as expected.
I'm trying to write a JScript wrapper, to sit at myprogram.js, be executed by Windows Script Host, and ship off to Node.js. Unfortunately, it doesn't seem like WScript's Exec command behaves like the UNIX exec command:
var shell = new ActiveXObject("WScript.Shell");
var proc = shell.exec("node .\\Library\\executable.js");
while (proc.Status === 0) {
WScript.Sleep(100);
}
WScript.Echo(proc.Status);
This buffers the program's output, and exposes it via some sort of JScript WshScriptExec object.
I need a script, or a feature, or some other way, to hand the entire terminal over to the command-line script I'm launching. Most usefully, I'd like to replace the JScript process that's executing, with the process for the command that I'm executing (i.e. UNIX-exec-y behaviour.) Is there any way to do this, or some other way to solve my problem?
Avoid the .js suffix completely so you get the same unadorned command name, e.g. executable, on all platforms.
Do so by setting bin in package.json as follows and npm will sort it:
{ "bin" : { "executable" : "./executable.js" } }
Source and further details: https://docs.npmjs.com/files/package.json#bin
I run a batch file as an external tool (by adding it in Tools->External tools) in VS2010 (I've checked the "Use Output Window" option). This batch file performs compilation as in VS command prompt. The project that I'm working on has makefiles for various folders, so I use the mk command to build.
In the batch file, I set up the VS environment and then run the following commands:
cd $directoryWhichContainsFileToBuild
mk
cd main //This directory contains the executable that is to be built
mk
I see the output of the first mk in the Output window but after that it just hangs. I also tried to use an echo after the first mk but even that doesn't get printed in the output window (the ones before it can be seen).
Somewhere I read that there is an issue with VS 2010 output window where it hangs after showing some output, although I couldn't really be sure that that is what's the issue here.
Do I need to enable some other VS setting? Has anybody else encountered this issue?
Thanks.
Update: I unchecked the "Use Output Window" and "Close on exit" option, and I see an extra statement: "Press any key to continue". On doing that however, their is no further processing of the batch file.
Update2: Got it to work by prefixing mk with "call".
Thanks all who tried.
It is always good in batch files to specify executables with full path and file extension instead of just the file name. This avoids often lots of problems.
Here was just mk used instead of mk.bat. Therefore on every compile the command line processor cmd.exe searches for mk.* and then checks if any of the found files have an extension listed in environment variable PATHEXT. The order of file extensions separated by a semicolon in PATHEXT defines the order of execution in case of a directory contains multiple mk.* files.
If a command being specified in a batch file not being an internal command of cmd.exe without path, command line processor searches first for a file with given name in current working directory. This is often one more cause of error. What is the current working directory on execution of the batch file?
Next if no file to execute can be found in current working directory, the command line processor searches in all folders being listed in environment variable PATH separated by semicolons.
So specifying in batch files edited only rarely an external application or another batch file with full path, file name and file extension, in double quotes if necessary because of 1 or more spaces in path or file name, helps command line processor to more quickly execute that application or batch file and avoids problems because of executable not found (unknown command).
Sure, when typing commands in a command prompt window, nobody wants to enter the executables with full path, name and extension. But for batch files it is always good to be not lazy and type files to be executed with full path and extension.
TripeHound has given already the explanation why the observed behavior occurred here.
If a batch file is executed from another batch file without using command call, the command line processor continues batch execution in the other batch file and does never come back. In a C/C++ program this is like using goto with the difference that parameters can be passed to the batch file containing the further commands to be executed next.
But running from within a batch file another batch file with call results in continuation of execution below the line calling the other batch file once the other batch file reaches end, except command exit is used in the called batch file without parameter /B.
So the solution here is using:
cd /D "Directory\Which\Contains\File\To\Build"
call "Path\Containing\Batch\File\To\Build\mk.bat"
rem With mk.bat not changing current working directory change working
rem directory to the directory containing the executable to be built.
cd main
call "Path\Containing\Batch\File\To\Build\mk.bat"
BTW: exit exits command processor, exit /B exits just current batch file. I'll give you three guesses why the parameter is B and not a different letter. Yes, B is the first letter of batch.
Writing as a separate answer instead of an update in the question itself as many readers see the header and skim to the answer: got it to work by prefixing mk with "call". (#TripleHound has also posted the conceptual reason for it in the comment above.)
I am using Windows 7
How can i run an input file (text file of commands) in an exe progam in CMD please.
Using other questions on the site, i have tried:
CMD /c ""C:/Program Files/Mplus/Mpluswin.exe" "C:/Users/jj/Desktop/mplus/test_mplus.inp""
which opens the input file in the program but does not run it
and this, which opens the program, but not the script
CMD /c "C:/Program Files/Mplus/Mpluswin.exe" < "C:/Users/jj/Desktop/mplus/test_mplus.inp"
Does this depend on the exe program?
Edit:
At present, the first command above launches the exe program and opens the text file within it (this is a file of program specific commands that will read in data, run calculations and output automatically). I can then run the commands in the exe program that has been opened (by selecting run in a menu) . But, I would like to pass the file to the exe program and it to be run automatically, ideally in the background. I am not sure of the correct terminology to use, so sorry if my description is unclear.
I've just noticed that you enclosed the entire term in an extra set of double quotes, and used linux forward slashes - try this batch file and also see if there is any error message on the console.
#echo off
cd /d "%userprofile%\Desktop\mplus"
"C:\Program Files\Mplus\Mpluswin.exe" "test_mplus.inp"
echo mplus was launched
pause