Hi everyone!, I'm working with PHP and I am having some problems with the system function. I hope you can help me, please.
First of all, I'm using lampp (xampp for linux) and ubuntu 10.4. In my server, in a directory located in /opt/lampp/htdocs/iris I have a program made in c which I need to execute but, when I do it, system returns an error. I replace that program to another that only has a cout and it returns an error too so the program it's not the problem, is the way that I call it or something like that. I wrote exactly this:
$resultado = system("./main libor ./datos/n4/4.jpg ./datos/n4/4.cod ./datos/n4/4.err);
and in $resultado it returns false so the program fails. I have used umask(0) and chmod("nombrearchivoX",0777) in order to made all the archives that I'm using reachable for all type of users.
I executed the command that I'm passing to system manually and it all goes well!, and I'm in the correct directory because I do a system("ls") and the program is there.
In the same directory, if I write an linux script and I use system("nameofthescript") it all goes well!! why not when I'm using a C++ compiled program??
Why can't I execute the program?, what am I doing wrong??
Thanks for all, all suggestions are welcome.
problem using system() in linux
Moderator: General Moderators
-
- Forum Newbie
- Posts: 1
- Joined: Fri Jul 09, 2010 1:19 pm
Re: problem using system() in linux
Try using absolute file paths (i.e. /directory1/directory2/main) for the command itself and its arguments.
Also redirect stderr to stdout like this
Also redirect stderr to stdout like this
Code: Select all
$result = system("/directory/command arg1 arg2 2>&1");
var_dump($result);
There are 10 types of people in this world, those who understand binary and those who don't