Running a system command from php

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Helo, my first post here....

I am trying to run an agent application that converts and imports two
tables from MS Access into mySql.
(Intelligent Converters - Access2mySql)
I have run similar scripts to do mysql dumps using the system function.
Not sure if the paths included in the parameters are correct:

function import_data() {
$sourceFile = "C:\Program Files\Intelligent converters\myAccessDB.mdb";
$tableFile = "C:\Program Files\Intelligent Converters\whichTables.txt";
system("/Program Files/Intelligent Converters/A2SAGENT.EXE
--dest=st_staff --src=$sourceFile --tab_file=$tableFile --mode=1");

This syntax works fine in command line prompt, but somehow it is not
working when called from php. I have tried two versionn of this (one
using user/pass - not shown) and the one above.

Any pointers on running this, and getting results.


Re: Running a system command from php

jsw_nz wrote:
Quoted text here. Click to load it

Hi John,

It might have something to do with user-rights, because you execute the  
command as the webserver user when you call the script from a webbrowser.
Try to debug it by passing in the second optional parameter to the  
system command, which is a reference variable to which the system  
command will write the output of the command.


system("/Program Files/Intelligent Converters/A2SAGENT.EXE
  --dest=st_staff --src=$sourceFile --tab_file=$tableFile --mode=1",  


Re: Running a system command from php

Hi Peter,

I condensed the string (just to simplify things), but still it does not
seem to work inside php/system command. I tested in standalone command the expression is correct. One thing as far as this script
is concerned is that the -dest=st_staff utilizes a mysql odbc DSN. I am
wondering if that is throwing it. As far as I know the agent
application requires this in order to function.

A2SAGENT.EXE --dest=st_staff --src=C:\ST_2005.mdb
--tab_file=C:\whichTables.txt --mode=1

The dump_var returns int(1) but the import is not occurring. Thanks for
your help.

Re: Running a system command from php

Hi John,

So, when you run the AS2Agent.exe command manually from the commandline,  
does it output anything?
If yes, then the return value of the system command will hold the last  
line of the output of the AS2Agent.exe command. So you could try storing  
that like:

$strLastLine = system("/Program Files/Intelligent Converters/A2SAGENT.EXE
  --dest=st_staff --src=$sourceFile --tab_file=$tableFile --mode=1",  

My instict still points into the userrights direction, so I'd check that.


Re: Running a system command from php

On Thu, 08 Sep 2005 21:25:23 -0700, jsw_nz wrote:

Quoted text here. Click to load it

I see two possible causes for errors here:

1) to call the program you do not use a drive letter, are you sure the
program is executed?

2) space in path name. Try escaping the spaces in the path names. Space
might be handled differently from a script than from command line.


Re: Running a system command from php

jsw_nz wrote:
Quoted text here. Click to load it

It's possible your system doesn't like the space in the command line.
It's also possible that the 's in variables are treated as escape

Try this:

$sourceFile = '"C:\Program Files\Intelligent
$tableFile = '"C:\Program Files\Intelligent
$cl = '"/Program Files/Intelligent Converters/A2SAGENT.EXE" ' .
      "--dest=st_staff --src=$sourceFile --tab_file=$tableFile


Re: Running a system command from php

Thank you Peter, Paul and NC for your pointers. The space in the path
to the executable was causing the problems. I copied the application to
the root, eliminating any spaces in the path and it now works. So just
a couple of questions/observations

(1) Within the context of calling system this a general
problem, regardless of the application being called, ie....would I
encounter this in any and all calls using paths that contains spaces.

(2) Paul, you had mentioned that tryiing to escape the spaces in the
path names might help. Familiar with escaping...but not sure how you
would escape the space.

Anyway now works. This forum is great, thanks all for your timely


Site Timeline