exec() Silent Death

Under Win32/Vista, PHP 5, I have a batch of files to convert and I'm
trying to script that in PHP.

The line below fails silently - while the hand-entered version (sans
the escapes of course) works correctly. I've tried system() and added
an output parameter to the exec() call, but the silence remains.

exec ("C:\\Program Files\\FWTools\\ogr2ogr-f \"MapInfo File\" f:\
\out2.mif f:\\tgr24001\\tgr24001cty00.shp");

Ideas on how to troubleshoot this are most welcome. --AS
ashore [ So, 06 Mai 2007 16:24 ] [ ID #1705785 ]

Re: exec() Silent Death

ashore wrote:
> Under Win32/Vista, PHP 5, I have a batch of files to convert and I'm
> trying to script that in PHP.
>
> The line below fails silently - while the hand-entered version (sans
> the escapes of course) works correctly. I've tried system() and added
> an output parameter to the exec() call, but the silence remains.
>
> exec ("C:\\Program Files\\FWTools\\ogr2ogr-f \"MapInfo File\" f:\
> \out2.mif f:\\tgr24001\\tgr24001cty00.shp");
>
> Ideas on how to troubleshoot this are most welcome. --AS
>
How do you execute the PHP script, from CLI or HTTP?

if CLI, the program you use don't report errors to the CLI if something goes
wrong.

if over HTTP, the convert process takes longer than the timeout time, so the
script will be terminated before it finish.

--

//Aho
Shion [ So, 06 Mai 2007 17:15 ] [ ID #1705786 ]

Re: exec() Silent Death

Hey, thanks. I added a sleep(25) call, same results. ????
ashore [ So, 06 Mai 2007 17:34 ] [ ID #1705787 ]

Re: exec() Silent Death

ashore wrote:
> Hey, thanks. I added a sleep(25) call, same results. ????

In your php.ini you have a max_execution_time setting, by default php will be
run in 30 sec, if it takes longer the script will be terminated. Using sleep()
will just make your script will have time to do even less.

You need to extend the max_execution_time or make the exec() to start the CLI
program in the background (I guess that DOS that microsoft bought once in the
time don't support to start things in the background, so this option is out of
question).

--

//Aho
Shion [ So, 06 Mai 2007 18:20 ] [ ID #1705789 ]

Re: exec() Silent Death

Thanks, but from the PHP manual re exec():

"... Note: If you start a program using this function and want to
leave it running in the background, you have to make sure that the
output of that program is redirected to a file or some other output
stream or else PHP will hang until the execution of the program
ends. ..."

AS
ashore [ So, 06 Mai 2007 22:53 ] [ ID #1705792 ]

Re: exec() Silent Death

On May 6, 3:24 pm, ashore <shor... [at] gmail.com> wrote:
> Under Win32/Vista, PHP 5, I have a batch of files to convert and I'm
> trying to script that in PHP.
>
> The line below fails silently - while the hand-entered version (sans
> the escapes of course) works correctly. I've tried system() and added
> an output parameter to the exec() call, but the silence remains.
>
> exec ("C:\\Program Files\\FWTools\\ogr2ogr-f \"MapInfo File\" f:\
> \out2.mif f:\\tgr24001\\tgr24001cty00.shp");
>
> Ideas on how to troubleshoot this are most welcome. --AS

i fyou hard coded the exec command and it works in a browser, then you
need to print out the dynamically generated command, and check that
the two are equal. My guess is that they aren't! For instance it would
be my guess that in your line above, the dynamically generated line
loses the "" around some paths and the call is broken there, and
fails.
You could try adding &2>1 in order to divert the errors to stdout to
see what the actual eror returned is.

Heres the way I would do it:
//assuming that "ogr2ogr-f" is a program name and that -f isnt an
argument.
//using single forward slashes which windows understnads just as well.
//using single quotes because you dont need php to parse for special
whitespace characters like \r or \n
$var1 = 'C:/Program Files/FWTools/ogr2ogr-f';
$var2 = 'MapInfo File';
//assuming f: is not a mapped or network drive
$var3 = 'f:/out2.mif';
$var4 = 'f:/tgr24001/tgr24001cty00.shp';

//any var that _might_ have spaces in it should be escaped
//overkill but it will escape all paths, so if there _are_ spaces
things will work
$command = '"'.$var1.'" "'.$var2.'" "'.$var3.'" "'.$var4.'"';
exec( $command );
shimmyshack [ Mo, 07 Mai 2007 01:51 ] [ ID #1706397 ]

Re: exec() Silent Death

On May 6, 3:24 pm, ashore <shor... [at] gmail.com> wrote:
> Under Win32/Vista, PHP 5, I have a batch of files to convert and I'm
> trying to script that in PHP.
>
> The line below fails silently - while the hand-entered version (sans
> the escapes of course) works correctly. I've tried system() and added
> an output parameter to the exec() call, but the silence remains.
>
> exec ("C:\\Program Files\\FWTools\\ogr2ogr-f \"MapInfo File\" f:\
> \out2.mif f:\\tgr24001\\tgr24001cty00.shp");
>
> Ideas on how to troubleshoot this are most welcome. --AS

I suppose I should add that you can change working directory uisng
chdir() to the dir of the executable, before calling it. This might
solve some issues with very badly written executables or batch files,
which expect a certain working directory.
shimmyshack [ Mo, 07 Mai 2007 01:53 ] [ ID #1706398 ]
PHP » alt.php » exec() Silent Death

Vorheriges Thema: iconv to strip out specfic language characters
Nächstes Thema: Debugging PHP with Eclipse PDT