【发布时间】:2018-06-09 21:53:54
【问题描述】:
我有一个 Octave(CentOS 6.6 上的 v. 4.0.0)代码,我通常像 octave-cli mycode someargument 一样运行。
我想从 Octave 命令行解释器调试这段代码。这是一个最小的工作示例:
$ cat somefunc.m
function somefunc
printf("hello world\n");
args = argv();
printf("args = %s\n", args{1});
endfunction
somefunc();
printf("this is the end\n");
这段代码运行如下:
$ octave-cli somefunc.m somearg
hello world
args = somearg
this is the end
我希望能够从命令行调试此代码,并传递 somearg 以便 argv() 捕获它,例如
$ octave-cli
octave:1> dbstop somefunc 4;
octave:2> somefunc somearg
stopped in /some/path/somefunc.m at line 4
4: printf("args = %s\n", args{1});
hello world
debug> dbcont
error: somefunc: A(I): index out of bounds; value 1 out of bound 0
error: called from
somefunc at line 4 column 5
octave:2>
但我不知道如何让argv() 读取命令行参数。我需要安装一个丑陋的开关吗?类似的东西:
if(is_interactive_mode)
args = "somearg";
else
args = argv();
end
在 Python 中我不会有这个问题,例如python -m pdb ./somefunc.py somearg 和 C(使用 Gdb)我会在 starting gdb 时传递参数,或者将传递给命令 run。
问题:从 octave 命令行以交互方式运行程序时,如何将命令行参数传递给程序?
【问题讨论】: