Visual C++ system command batch file - command-line

When I type the name of a batch file on the command line, it executes just fine, but when I run a Vis C++ program which uses the system("gen.bat") command, it doesn't execute it!
Here is how I'm doing it:
int ret = system("gen.bat");

You should specify the full path of the batch file like this:
int ret = system("C:\\folder_name\\gen.bat");

Related

Matlab doesn't recognize user environmental variable

I installed an application named lqns in the path: /home/robb/Research/dist/lqns-6.2/lqns (lqns is a folder containing the executable lqns). I want the program to be executed in command line simply calling lqns in the shell, I solved this adding to the file ~/.bashrc the line:
export PATH=$PATH:/home/robb/Research/dist/lqns-6.2/lqns
And it works with no issue. I am now trying to execute this program inside a Matlab script, running:
[status, ~] = system("lqns " + filename, '-echo');
Where filename is the path of an input file. I get the error message:
/bin/bash: line 1: lqns: command not found
Running the exact same command with the shell I get no error: the program runs with no problem generating the relative output.
Running getenv('PATH'); in Matlab and printenv PATH on my OS shell I indeed get two different results: Matlab does't have the path to lqns. I even tried editing manually the files /etc/environment, /etc/bash.bashrc and /root/.bashrc, with no result. How can I solve this issue?
you need to launch matlab by typing matlab in a terminal, not by double clicking on its shortcut from your desktop. (or even typing ./matlab in a terminal from your desktop)
it's up to the operating system to determine what double clicking does, and it's not guaranteed to execute most of your shell initialization scripts (or even launch it from the correct shell to begin with).
more info at Why are environment variables not resolved when double-clicking .desktop file?

how to execute cmd command from unity?

I want to write a particular command in script and execute it directly in cmd from unity for example here I am writing a simple change directory command but it is not executing directly rather I have write on my own the sample code is below
string pathToExe = Application.dataPath.Replace(#"/", #"\") + "\\Plugins";
string command = "D:";
Process process = Process.Start("cmd.exe", command);
process.WaitForExit();
process.Close();
enter image description here

Executing sbt in command line via python script and outputting to file

I have a set of json files in directory /Desktop/jsons, and I have a Scala script which takes in a json and outputs stuff. I can run it manually in the terminal by cding into the directory of the Scala script (/Me/dev/scalastuff) and running
sbt --error "run /Desktop/jsons/jsonExample.json",
which outputs the stuff I want in the terminal.
I want to write a Python script which does this automatically and additionally outputs a json file with the "stuff" thats outputted by the Scala script.
My issues right now are using subprocessing. When I try to run
BASEDIR = '/Me/dev/scalastuff'
p = subprocess.Popen(['sbt --error "run /Desktop/jsons/jsonExample.json"'], cwd = BASEDIR, stdout = subprocess.PIPE)
out = p.stdout.read()
print out
I get OSError: [Errno 2] No such file or directory.
I'm completely stumped as to why this is occurring. I'm new to subprocess, so be light on me!
popen in python takes a list of shell arguments. You're passing only one!
So it's trying to execute a file named wholly 'sbt --error "run /Me/Desktop/jsons/jsonExample.json"'.
Obviously, this doesn't work.
If you use popen; only pass a simple array -- you needn't care about escaping:
subprocess.popen(['sbt', '--error', 'run /Me/Desktop/...'], cwd = BASEDIR, stdout = subprocess.PIPE)

How to run batch file(having command to run .exe file) from matlab?

I am trying to run a batch file from matlab. In my batch file I have the command to run the .exe file. I am using the dos('myfile.bat') command to run the batch file from matlab, but it is showing the error as
"file.exe is not recognized as an internal or external command, operable program or batch file."
What exactly is this error? And how should deal with this.
If I understand correctly you try to run an exe in MatLab. You don't have to put it inside a batch file, you only need to call it in this way:
! file.exe
or you can setup a string and call it with eval:
command = [ '! ' filename ];
eval( command );
But I think the problem is that you should specify the path of exe (or bat if you like) with absolute path.
! D:\Development\Stuff\App.exe
And of course pass the arguments if required.
! D:\Development\Stuff\App.exe -arg1 -arg2

Algorithm to read and write command line string

I'm trying to write a program that can read a command string and validate it (get the name of the command and it's arguments), change those arguments and then rewrite the command string dynamically.
I'm looking for an Algorithm or regEx that can parse a command string. I'm familiar with DOS 6.2 and batch files but I know very little about Mac like terminal, unix, shell, etc which is what I'm using. I'm not sure if the arguments is a different syntax from one command to the next.
More info:
Things I have to do is validate that a command line is formatted correctly, for example, where paths to files have quotes around them or escape spaces if they are there. I would like it to be generic so that it can work with any command.
I'm using a Mac so I can test in Terminal.
#include<stdio.h>
main(int argc,char *argv[])
{
if(execlp(argv[1], argv[1], argv[2], "/usr/", (char *) 0)==-1)
printf("This is not valid command\n");
exit(0);
}
Run the program :
./a.out ls -lhrt
This program handled more than one options.
which directory you want change it instead of the "/usr" directory
You run the program dynamically and change the command and options .