hi there, i need to call some matlab functions from java and i've found useful tips on this site, but i have got some problems when trying them on a simple example :S i just want to pass a number as an argument for the function i'm calling, but can't get a good result!
Process p= Runtime.getRuntime().exec("C:/Documents and Settings/DANIEL/workspace/ProbandoMatlab/src/pvt.exe 100" );
i have tried with a string array and a lot of different ways as well... but no idea
cmd= "C:/Documents and Settings/DANIEL/workspace/ProbandoMatlab/src/pvt.exe"; cmd= "100";
Process p= Runtime.getRuntime().exec(cmd);
any ideas? could someone help me?? thanks in advance dani
If you're on Windows, you should probably use backslash \ rather than forward slash /. Since it's in a Java literal you will have to double each backslash. Also, you may need to put quotes around the whole path, because of the spaces inside "Documents and Settings". Those quotes will also need to be escaped with backslashes. So:
Please first of all see whether you can pass argument to matlab from command prompt You may see this post of mine at Other Java APIs forum for help as you are on windows. I have posted a code to run bat file which in turns execute command.
Help gets you when you need it!
Joined: Jan 15, 2008
hi! thank you very much for your answers. as i can see, it's not a problem of the slashes, because i can call matlab functions with no problem and read the sentences displayed when sending no arguments, the problem comes if i send an argument...
Process p= Runtime.getRuntime().exec("C:/Documents and Settings/DANIEL/workspace/ProbandoMatlab/src/pvt.exe 100");
_________________________________________ String  parametros = new String; parametros= "C:/Documents and Settings/DANIEL/workspace/ProbandoMatlab/src/pvt.exe" ; parametros= ""; parametros= "100";
Process p= Runtime.getRuntime().exec( parametros ); _________________________________________ String  parametros = new String; parametros= "C:/Documents and Settings/DANIEL/workspace/ProbandoMatlab/src/pvt.exe" ; parametros= "100";
Process p= Runtime.getRuntime().exec( parametros );
if i do any these posibilities, "100" as an argument, i get three numbers as a result (trying with different numbers, i get as many result numbers as digits in my argument), when i'm just expecting one!!!
hope somebody knows what's going on here.... thank you very much
Joined: Jan 15, 2008
i found out the problem is not when passing arguments, the problem is the matlab .exe. i dont know why but it converts in ascii code all the inputs, so i get strange numbers at the output :S
thanks for the answers
Joined: May 09, 2002
See if there is a way on the Java side to send data as ascii.
An easier way than using Runtime.exec() is to make use of the matlabcontrol Java library. You can use feval to directly call MATLAB functions and provide any number of arguments directly. To get started, take a look at the walkthrough.