0

I am trying to run an octave script through PHP. I already googled and found some results but none of them are working for me. I tried with exec() and system(). I even created a batch file which calls 'octave myScript.m" and called this bat file using system() of PHP but it doesnt seem to work. In the browser page I am just seeing 'C:/FOLDER_PATH>octave myScript.m". The octave script simply creates a new file and writes some text to it. When i directly run the bat file (by double-clicking on it), the file is getting created properly. I also added folder path to octaverc file but it doesnt seem to work. I need to do some image processing in octave for which I already wrote the script. I need to invoke this script on a client request and send the result to back the client. I am checking the invocation process through a sample script which as I mentioned earlier creates a new file. What am I doing wrong?

My php code is this:

$cmd = "cmd /c C:\PATH_TO_BAT_FILE\myBat.bat";
exec($cmd,$output);
system($cmd);
echo implode ("\n",$output);

Note that my path contains double backslashes to avoid escape sequence characters

My bat file is this

octave temp.m

My octave code(temp.m) is this

fid = fopen("helloScript.txt",'w');
fprintf(fid,"Hello world!");
fclose(fid);

Ouput on the webpage is this:

C:\PATH_TO_BAT_FILE>octave temp.m C:\PATH_TO_BAT_FILE>octave temp.m

I can see in the task manager that a new process is getting created whenever I run the PHP script in browser (I am guessing that it is cmd). Also, when i change my bat file to

echo hello

I am able to see the following in my browser page

 C:\PATH_TO_BAT_FILE>echo hello hello C:\PATH_TO_BAT_FILE>echo hello hello 

So this could mean that the bat file is getting executed properly. But when I replace the bat file script with 'octave MY_FILE.m' I am not able to see the output. It may mean that my octave is not configured properly? or is there something I am missing?

Any help would be appreciated.

Thanks

5
  • If you can see php sourcecode in the source then you dont have php enabled. Commented Jan 22, 2014 at 5:20
  • Could you please explain? I didnt understand Commented Jan 22, 2014 at 5:28
  • Its what I deduced from: In the browser page I am just seeing 'C:/FOLDER_PATH>octave myScript.m". Commented Jan 22, 2014 at 5:30
  • Actually can you show us what code you are trying. Commented Jan 22, 2014 at 5:32
  • edited the question to include my code Commented Jan 22, 2014 at 5:39

2 Answers 2

0

If you are going to run the batch file to create it in php then the php command should be like this.

exec('cmd.exe /c C:\path\to\test.bat');
Sign up to request clarification or add additional context in comments.

4 Comments

I already tried that. It is not working. My php code is this:
Would it not be cmd.exe /c C:\\path\\to\\test.bat? else your get tabs for the \t
@LozCherone Yes I believe you are right, it shouldn't need to be escaped unless you use double quotes. Changed it.
edited the question. Hope it makes my question clearer
0

This is embarassing but I solved it by giving full path. In the bat file I specified the complete path of the octave.exe (C:\Software\PATH_TO_OCTAVE.EXE) and the complete path of the '.m' file. In my php, I just used exec()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.