通过PHP Windows的八度脚本 [英] Octave script through php windows

查看:120
本文介绍了通过PHP Windows的八度脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过PHP运行八度脚本.我已经在Google上搜索并找到了一些结果,但没有一个对我有用.我尝试了exec()和system().我什至创建了一个名为'octave myScript.m'的批处理文件,并使用PHP的system()调用了该bat文件,但似乎无法正常工作.在浏览器页面中,我只是看到'C:/FOLDER_PATH> octave myScript.m. ".八度脚本仅创建一个新文件并向其中写入一些文本.当我直接运行bat文件时(通过双击它),该文件已正确创建.我还向octaverc文件添加了文件夹路径,但它似乎不起作用.我需要用八度做一些图像处理,而我已经为其编写了脚本.我需要在客户端请求上调用此脚本,并将结果发送回客户端.我正在通过示例脚本检查调用过程,正如我前面提到的,该脚本创建了一个新文件.我在做什么错了?

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?

我的php代码是这样的:

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

我的蝙蝠文件是这个

octave temp.m

我的八度音阶(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

每当我在浏览器中运行PHP脚本时,我都可以在任务管理器中看到正在创建一个新进程(我猜它是cmd). 另外,当我将蝙蝠文件更改为

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 

因此,这可能意味着bat文件正在正确执行.但是,当我将蝙蝠文件脚本替换为'octave MY_FILE.m'时,我看不到输出.这可能意味着我的八度音程配置不正确?还是我缺少什么?

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?

任何帮助将不胜感激.

谢谢

推荐答案

这很令人尴尬,但是我通过给出完整路径解决了它.在bat文件中,我指定了octave.exe的完整路径(C:\ Software \ PATH_TO_OCTAVE.EXE)和'.m'文件的完整路径. 在我的php中,我只使用了exec()

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()

这篇关于通过PHP Windows的八度脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆