在AIX6.1 (KSH版本M-11/16/88F)的C代码中,非常奇怪的行为:
int main(int argc, char *argv[]){
int status;
//...
// parse arguments
// do things
//...
status=system("echo hello");
}有时,system调用失败(即使在构建系统命令时没有考虑到args,即"echo hello“)。
当它失败时,我会收到这样的消息:
[[[: 0403-057 Syntax error通过以下方式跟踪可执行文件:
truss -aef -o truss.log my_exec args...(注意-e选项用于查看每个exec系统调用中传递的环境字符串)
我注意到,在某个时候,通过添加一个“损坏”变量RDV_CALCULATE_M[[[[来修改环境。,这是语法错误的原因。实际上,如果在shell中直接发出此命令:
export RDV_CALCULATE_M[[[[我也犯了同样的错误:
[[[: 0403-057 Syntax error因此,到目前为止,我确信直接改变环境的不是我的代码,而是我使用的库中的一些东西。
int main(int argc, char *argv[]){
int status;
/*...
parse arguments
do things with external library
external library messes with the environment
*/
status=system("echo hello"); --> fails because environment is corrupted
}发布于 2016-11-05 11:16:52
错误消息表明一些ksh或bash代码被输入到Bourne。
确保您再次检查手册页的system(3)。AIX (以前是)基于System,所以它几乎可以肯定地调用/bin/sh。即使它是到Korn的链接,当被称为/bin/sh时,它的行为也可能有所不同。
Solaris也是基于System的,它有一个truss (http://opensolarisforum.org/man/man1/truss.html)实用程序。我听说AIX有类似的东西;它可以帮助您了解调用的shell是什么,以及是否有任何shell函数起作用。
我希望我能提供更多帮助,但我无法在线找到AIX手册页,而且我最后一次使用AIX是版本3或4。
https://stackoverflow.com/questions/40427391
复制相似问题