I tried to use exec function to run pandoc command line tool to do my task, but there had been an error code 43.

It made me felt confused, so I redirected the output flow to a local file.

$cmdStr='/path/pandoc /path/weiyang.md -o /path/weiyang.pdf > debug.log 2>&1';
$output = "";
$ret_code = 0;
exec( $cmdStr, $output, $ret_code );

if( 0 != $ret_code )
{
	echo "[error] ret_code: " . $ret_code . "\n" . $output . "\n" . $cmdStr;
//...

Analyze the debug file, I got the following info.

$ cat debug.log 
lstat(./pdflatex) failed: ./pdflatex: No such file or directory
kpathsea: Can't get directory of program name: ./pdflatex
lstat(./pdflatex) failed: ./pdflatex: No such file or directory
kpathsea: Can't get directory of program name: ./pdflatex
Error producing PDF.

But the same command line statement works when I run it on the terminal. I guess its environment variable is not correct in PHP EXEC function.

Change the original command string, input the path of pdflatex to PATH.

$cmdStr='export PATH=$PATH:/usr/bin/;/path/pandoc /path/weiyang.md -o /path/weiyang.pdf > debug.log 2>&1';

The whole workflow seems ok.

Tips:

We can write a small php script file to test our sectional code.

<?php
$cmdStr='/path/pandoc /path/weiyang.md -o /path/weiyang.pdf > debug.log 2>&1';
exec($cmdStr);
?>
Categories: ToolWeb

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments

XML To JSON
: Input your strings, the tool can convert XML to JSON for you.

X
0
Would love your thoughts, please comment.x
()
x