Primoz Rome
Primoz Rome

Reputation: 11031

perl script called from PHP generates file with zero bytes size

I am calling external Perl script to convert DXF file to SVG, but when script is called from PHP the output SVG file is always 0 bytes. When executing the same command from terminal the output SVG file is OK.

I am executing command via PHP system() and also tried exec() and popen() but I always have the same result.

dxf2svg.pl perl script source code: http://pastebin.com/fE2BcUqE

command that I am executing:

perl /path/dxf2svg.pl "/path_to_dxf/file.dxf" ">/output_path/file.dxf"

Outup path is writable to PHP user, so this is not the problem.

Upvotes: 1

Views: 658

Answers (1)

TLP
TLP

Reputation: 67900

After debugging in chat it was discovered that the line

open (WRITECSS, ">output.css")or die("error in Writing CSSFile");

Was the culprit. Since running the script from the command line created a file with the wrong write permissions, the script died at this statement. Since errors were not returned to PHP, the error was silent.

The solution was to chmod the output CSS file.

Debugging was done by redirecting STDERR from perl to a file, and adding the error reporting variable $! to the die statement:

open STDERR, ">>", "somefile" or die $!;
open (WRITECSS, ">output.css")or die("error in Writing CSSFile: $!");

Upvotes: 2

Related Questions