PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
It is currently Sat Dec 05, 2020 9:20 am

All times are UTC - 5 hours

Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri Jul 09, 2010 1:21 pm 
Forum Newbie

Joined: Fri Jul 09, 2010 1:19 pm
Posts: 1
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.

PostPosted: Tue Jul 13, 2010 1:25 am 
DevNet Master
User avatar

Joined: Wed Jun 27, 2007 9:44 am
Posts: 4313
Location: Sofia, Bulgaria
Try using absolute file paths (i.e. /directory1/directory2/main) for the command itself and its arguments.
Also redirect stderr to stdout like this
Syntax: [ Download ] [ Hide ]
$result = system("/directory/command arg1 arg2 2>&1");

There are 10 types of people in this world, those who understand binary and those who don't

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours

Who is online

Users browsing this forum: No registered users and 4 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group