Page 1 of 1

Get error information from system()

Posted: Wed Jul 01, 2009 11:21 am
by mtgilsbach
Hi,

I am trying to run a fairly simple AWK script against a text file using the php system() command, like this:

$awk_command = system("awk -f simple.awk file_name.txt", $ret_val)

I can run the AWK command from the command line and it works just fine. But it doesn't seem to want to run from my PHP page. $ret_val just keeps coming back as 1.

This thing actually works fine on a UNIX machine, but I need to get it to run on a Windows machine.

Is there any way to get more detailed information on why the thing failed?

Thanks,
Mike

Re: Get error information from system()

Posted: Wed Jul 01, 2009 11:29 am
by BornForCode
Why do you think that you have awk on Windows?

Re: Get error information from system()

Posted: Wed Jul 01, 2009 11:30 am
by mtgilsbach
Because I put it there. I added it to the Windows PATH. It works fine from the command line.

I just can't get my PHP page to run it.

-Mike

Re: Get error information from system()

Posted: Wed Jul 01, 2009 11:33 am
by BornForCode
If you are running under IIS just give the rights permission to your web user IUSR_<servername> to the command line tool (cmd.exe).

Re: Get error information from system()

Posted: Wed Jul 01, 2009 11:35 am
by mtgilsbach
I'm sorry. I should have mentioned that I am running Apache on Windows, not IIS.

My bad.

-Mike

Re: Get error information from system()

Posted: Wed Jul 01, 2009 11:41 am
by BornForCode
Can you please tell us if you can run other system commands, this will help to understand where error is encountered.

Re: Get error information from system()

Posted: Wed Jul 01, 2009 11:47 am
by mtgilsbach
Yes, I can run a simple system command like "dir" and it works, showing me the directory information for the directory where the PHP page is located.

I am seeing some entries in the error log to the effect of "awk is not recognized as an external or internal command..."

I am starting to think I need to add something to my httpd.conf to make Apache aware of the Windows environment variable...?

-Mike

Re: Get error information from system()

Posted: Wed Jul 01, 2009 11:52 am
by BornForCode
Yea, that should be the solution. Check this out: http://httpd.apache.org/docs/2.2/platfo ... iling.html
So probably try to use gawk instead awk :).

PS Why are you doing this to us, you traitor :twisted:

Re: Get error information from system()

Posted: Tue Jul 07, 2009 11:50 am
by mtgilsbach
OK. I got it fixed. Adding the following to my conf file did the trick:

SetEnv awk C:\awk\bin

Don't worry, I am using a UNIX machine for production. I am only using Windows as a local test machine because I don't have a local UNIX machine available to me for testing. :lol:

Thanks for your help!

-Mike

Re: Get error information from system()

Posted: Thu Jul 16, 2009 4:02 am
by paulgodard
Hi everyone
I am also using system() in php 5. I use it for executing mysql/mysqldump commands and I have a few issues. BTW, my webserver is unix but my local server is Mac OS-X.

1/ How to get the error message normally given in command line mode (Terminal).
Here is what I have in my script :
$Query = "/usr/bin/mysql -uLOGIN -pPASSWORD DATABASE < ../../_mysql/FILE.sql";
$ErrSystem = system($Query, $Result);
When everything goes well, $Result = 0. If there is an error, $Result = 1 but $ErrSystem is empty or false.
I read that $ErrSystem should content the last error line (the one I get on the command line mode), isn't it?
What is wrong here?

2/ On my Mac, I have to use root level to execute mysql command via system() in php. Is it the same on unix?
safe_mode is off on my Mac, however I can execute a coomand (mysql) which is outside of the path of the php script. Is this normal?