从php调用八度音阶脚本时出现意外输出 [英] Unexpected output while calling octave script from php

查看:87
本文介绍了从php调用八度音阶脚本时出现意外输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从PHP调用Octave脚本并将参数传递给它.但是我得到了意外的输出.

I am calling Octave script from PHP and passing parameters to it. But I get the unexpected output.

我用来传递参数并调用Octave脚本的PHP代码是:

The PHP code I'm using to pass arguments and call the Octave script is:

$a=8;
$b=3;
$cmd = "C:\Octave\Octave4\bin\octave-cli C:\wamp\www\dspace\add.m $a $b";
$ex = passthru($cmd, $op);
var_dump($ex);

我的Octave脚本:

My Octave script:

arglist = argv();
 a = arglist{1};
 b = arglist{2};

function f (a,b)
  a + b
endfunction

printf(f(a,b));

输出结果为:

ans = 107

预期输出为:

11

我该如何解决?

推荐答案

您正在添加 ASCII代码表示字符"8"(即56)和"3"(即51),因此结果为107.将字符串转换为数字:

You are adding the ASCII codes for the character "8" which is 56 and "3" which is 51 so the result is 107. Convert the strings to numbers:

arglist = argv();

a = str2num (arglist{1});
b = str2num (arglist{2});

function ret = f (a,b)
  ret = a + b;
endfunction

printf("%i", f(a,b));

这篇关于从php调用八度音阶脚本时出现意外输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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