简体   繁体   English

从CGI脚本调用System()

[英]System() call from a cgi script

For my assignment, I have a cgi script (C program) and a program that I want to call from the script using system(). 对于我的作业,我有一个cgi脚本(C程序)和一个要使用system()从脚本中调用的程序。 Both in cgi-bin/ and chmodded to 755. I know that the system call I make in my cgi program is valid (the path is correct, the command is correct...) yet the call always fails. 在cgi-bin /和chmodded中都为755。我知道我在cgi程序中进行的系统调用是有效的(路径正确,命令正确...),但调用始终失败。 I checked the working directory during the execution of the cgi-script and it is correct. 我在执行cgi-script时检查了工作目录,它是正确的。 If I run the same call in bash it works, but in my menu program it doesn't work. 如果我在bash中运行相同的调用,则可以,但是在我的菜单程序中,它不起作用。

It's strange since the system call was working when I ran the server on my computer (using python -m CGIHTTPServer), but when I placed the website on my university's server which is where it has to be, everything works except for the system() call. 奇怪的是,当我在计算机上运行服务器(使用python -m CGIHTTPServer)时,系统调用正在运行,但是当我将网站放置在大学所在的服务器上时,一切正常,除了system()呼叫。 So it seems like it has something to do with permissions. 因此,似乎与权限有关。

Here's the call in question, if it's any help: 这是有问题的电话,如果有帮助的话:

    sprintf(systemCall, "passweb -add %s", username);
    exitStatus = system(systemCall); //always 1

Apparently, I had to add a "./" in front of the executable path. 显然,我必须在可执行路径的前面添加“ ./”。

Like so: sprintf(systemCall, "./passweb -add %s", username); 像这样: sprintf(systemCall, "./passweb -add %s", username);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM