1

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.

2
  • It's fact that the problem is in php script. Can you show it too? Commented Jun 1, 2012 at 14:30
  • One guess is that your weird open statement with included MODE is messing things up. I.e. that PHP turns it into redirection, and overwrites the file after the perl script is done. However, that should cause your perl script to die since it cannot open to a file name which is an undefined value. Commented Jun 1, 2012 at 14:44

1 Answer 1

2

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: $!");
Sign up to request clarification or add additional context in comments.

6 Comments

Original perl script had this line as open (WRITECSS, ">output.svg"). I just changed the script so that I can supply the output file. I will try the suggested changes and confirm the result! UPDATE: the same result as before! The output file is still Zero Bytes :(. Tried the command from terminal and it works well as before! From PHP the same situation!
@PrimozRome You can just check the PHP error log (apache?) and see if you find those errors there. But you should be aware that not using hard coded open modes is a very bad idea, and also a security risk. Someone could give the argument "| rm -rf /" and then you are screwed.
Regarding the security issue, thanks for the notes, I will make sure this doesn't happen. Nothing in Apache error log, access log looks fine.
changed Perl code to open (WRITEFILE, ">", $ARGV[1])or die("error in Writing WriteFile"); and changed my command to: 'perl dxf2svg.pl "/path_to_dxf/p16uka04111fhu3r811971gtbgj41.dxf" "/svg_out_path/p16uka04111fhu3r811971gtbgj41.svg"'
Try reverting back to the original, hard coded, open and see if that helps.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.