exec() function, cmd, background printing
Moderators: egami, macek, gesf
Hi,
i need a little bit of your help with using the exec() function under Windows 7.
When i try:
exec('"C:\Program Files (x86)\Foxit Software\Foxit Reader\Foxit Reader.exe" C:\test.pdf') or die("It doesn't work");
it ends up with Interactive Service Detection (foxit opens my file in the "background" of my desktop)
but when i try to execute the same command with "/p" switch:
exec('"C:\Program Files (x86)\Foxit Software\Foxit Reader\Foxit Reader.exe" /p C:\test.pdf') or die("It doesn't work");
it doesn't even come to the Interactive Service Detection... i get the "It doesn't work" msg.
When i execute *.bat with same cmds under command line it works perfect. What i want is to get a silent printing in the background using foxit or adobe pdf readers.
thank you.
i need a little bit of your help with using the exec() function under Windows 7.
When i try:
exec('"C:\Program Files (x86)\Foxit Software\Foxit Reader\Foxit Reader.exe" C:\test.pdf') or die("It doesn't work");
it ends up with Interactive Service Detection (foxit opens my file in the "background" of my desktop)
but when i try to execute the same command with "/p" switch:
exec('"C:\Program Files (x86)\Foxit Software\Foxit Reader\Foxit Reader.exe" /p C:\test.pdf') or die("It doesn't work");
it doesn't even come to the Interactive Service Detection... i get the "It doesn't work" msg.
When i execute *.bat with same cmds under command line it works perfect. What i want is to get a silent printing in the background using foxit or adobe pdf readers.
thank you.
try using double slashes
Code: Select all
exec("C:\\Program Files (x86)\\Foxit Software\\Foxit Reader\\Foxit Reader.exe C:\\test.pdf")
you also will have to check the rights/permission for Foxit reader.exe. If it is set in such a way that only "system" can execute it then you will not be able to execute it using exec() without making appropriate changes to the permissions.
1. Foxit reader.exe has full rights for all user on my win7
2. "You will have to escape any other double quotes in between the full command"
something like that:
exec("\"C:\Program Files (x86)\Foxit Software\Foxit Reader\Foxit Reader.exe" /p C:\test.pdf \")
im not sure, becouse it doesnt work anyway.
2. "You will have to escape any other double quotes in between the full command"
something like that:
exec("\"C:\Program Files (x86)\Foxit Software\Foxit Reader\Foxit Reader.exe" /p C:\test.pdf \")
im not sure, becouse it doesnt work anyway.
try this
Also - when you run foxitreader.exe from command line does it open up a window. what does foxitreader.exe do?
Code: Select all
exec("C:\\Program Files (x86)\\Foxit Software\\Foxit Reader\\Foxit Reader.exe /p C:\\test.pdf ")
When i run this:
"C:\\Program Files (x86)\\Foxit Software\\Foxit Reader\\Foxit Reader.exe /p C:\\test.pdf"
in win cmd it works
but when i try:
exec("C:\\Program Files (x86)\\Foxit Software\\Foxit Reader\\Foxit Reader.exe /p C:\\test.pdf ");
it happens nothing...
"C:\\Program Files (x86)\\Foxit Software\\Foxit Reader\\Foxit Reader.exe /p C:\\test.pdf"
in win cmd it works
but when i try:
exec("C:\\Program Files (x86)\\Foxit Software\\Foxit Reader\\Foxit Reader.exe /p C:\\test.pdf ");
it happens nothing...
try this:
Code: Select all
exec("C:\\Program Files (x86)\\Foxit Software\\Foxit Reader\\Foxit Reader.exe /p C:\\test.pdf",$output);
var_dump($output);
try this (ignore the previous one):
Code: Select all
$rawoutput = exec("C:\\Program Files (x86)\\Foxit Software\\Foxit Reader\\Foxit Reader.exe /p C:\\test.pdf 2>&1", $output,$retcode );
echo '<br>Output is: ';
var_dump($output);
echo '<br/>';
echo 'return code is: ';
var_dump($retcode);
echo '<br> raw output is: ';
var_dump($rawoutput);
Result o got:
Output is: array(2) { [0]=> string(66) "'C:\Program' is not recognized as an internal or external command," [1]=> string(31) "operable program or batch file." }
return code is: int(1)
raw output is: string(31) "operable program or batch file."
Output is: array(2) { [0]=> string(66) "'C:\Program' is not recognized as an internal or external command," [1]=> string(31) "operable program or batch file." }
return code is: int(1)
raw output is: string(31) "operable program or batch file."
so, you can see that this is a space problem for the "Program Files" directory.
go to your command prompt, move to c: and type dir /x. it will then list all folder names. before the folder names, you will the folder name without spaces. For example: for my "Program Files" directory it shows PROGRA~1 as the shortened name.
see this, when I do dir /x at c:\> i get this:
You need to find the shortened directory name for each of the directory that you are using in your exec(). if you do not see a shortened name, for e.g. above, i don't have a shortened name for 'tmp' folder, then you have to use the available name which is 'tmp'. Go ahead and replace all your folder names (if shortened name is available) in your exec command.
go to your command prompt, move to c: and type dir /x. it will then list all folder names. before the folder names, you will the folder name without spaces. For example: for my "Program Files" directory it shows PROGRA~1 as the shortened name.
see this, when I do dir /x at c:\> i get this:
Code: Select all
07/18/13 11:52 AM <DIR> PROGRA~1 Program Files
02/24/13 11:45 AM <DIR> tmp
- Attachments
-
- dir_snap.jpg (13.33 KiB) Viewed 14453 times
As you said, i got:
$rawoutput = exec("C:\\PROGRA~2\\FOXITS~1\\FOXITR~1\\FOXITR~1.exe /p C:\\test.pdf 2>&1", $output,$retcode );
as result:
Output is: array(0) { }
return code is: int(0)
raw output is: string(0) ""
and still nothing
$rawoutput = exec("C:\\PROGRA~2\\FOXITS~1\\FOXITR~1\\FOXITR~1.exe /p C:\\test.pdf 2>&1", $output,$retcode );
as result:
Output is: array(0) { }
return code is: int(0)
raw output is: string(0) ""
and still nothing
did you check if test.pdf was created in C:\> ?
now, try this:
or even this
I can give you only suggestions as I am not able to try this on my side.
now, try this:
Code: Select all
$rawoutput = exec("C:\\PROGRA~2\\FOXITS~1\\FOXITR~1\\FOXITR~1.exe /p C:\\test.pdf", $output,$retcode );
Code: Select all
$rawoutput = exec("C:\PROGRA~2\FOXITS~1\FOXITR~1\FOXITR~1.exe /p C:\test.pdf", $output,$retcode );
0) file test.pdf exists on C:\
1) $rawoutput = exec("C:\\PROGRA~2\\FOXITS~1\\FOXITR~1\\FOXITR~1.exe /p C:\\test.pdf", $output,$retcode );
same, nothing happens
2) $rawoutput = exec("C:\PROGRA~2\FOXITS~1\FOXITR~1\FOXITR~1.exe /p C:\test.pdf", $output,$retcode );
file not found or could not be opened on foxit after the stupid windows interactive service detection window appears...
I give up...
1) $rawoutput = exec("C:\\PROGRA~2\\FOXITS~1\\FOXITR~1\\FOXITR~1.exe /p C:\\test.pdf", $output,$retcode );
same, nothing happens
2) $rawoutput = exec("C:\PROGRA~2\FOXITS~1\FOXITR~1\FOXITR~1.exe /p C:\test.pdf", $output,$retcode );
file not found or could not be opened on foxit after the stupid windows interactive service detection window appears...
I give up...
test.pdf exists on C: drive, so I am not sure what you trying to do.
Anyway, try using passthru instead of exec
Anyway, try using passthru instead of exec
Code: Select all
passthru("C:\\PROGRA~2\\FOXITS~1\\FOXITR~1\\FOXITR~1.exe /p C:\\test.pdf");
try all these, one at a time. Also, "Brother MFC-7840W" is my local printer name
Code: Select all
passthru("C:\\PROGRA~2\\FOXITS~1\\FOXITR~1\\FOXITR~1.exe //p C:\\test.pdf");
exec("C:\\PROGRA~2\\FOXITS~1\\FOXITR~1\\FOXITR~1.exe /t C:\\test.pdf 'Brother MFC-7840W'");
exec("C:\\PROGRA~2\\FOXITS~1\\FOXITR~1\\FOXITR~1.exe //t C:\\test.pdf 'Brother MFC-7840W'");
passthru("C:\\PROGRA~2\\FOXITS~1\\FOXITR~1\\FOXITR~1.exe /t C:\\test.pdf 'Brother MFC-7840W'");
passthru("C:\\PROGRA~2\\FOXITS~1\\FOXITR~1\\FOXITR~1.exe //t C:\\test.pdf 'Brother MFC-7840W'");
for the examples that I gave, you should be using $output, $retcode and $rawoutput. Only then we can see what is happening.
echo '<br>Output is: ';
var_dump($output);
echo '<br/>';
echo 'return code is: ';
var_dump($retcode);
echo '<br> raw output is: ';
var_dump($rawoutput);
echo '<br>Output is: ';
var_dump($output);
echo '<br/>';
echo 'return code is: ';
var_dump($retcode);
echo '<br> raw output is: ';
var_dump($rawoutput);
passthru has only 2 arguments, so retcode was skiped, those are the results, the order is the same
Output is: int(0)
return code is:
raw output is: NULL
Output is: array(0) { }
return code is: int(-1073741819)
raw output is: string(0) ""
Output is: array(0) { }
return code is: int(0)
raw output is: string(0) ""
Output is: int(0)
return code is:
raw output is: NULL
Output is: int(0)
return code is:
raw output is: NULL
Output is: int(0)
return code is:
raw output is: NULL
Output is: array(0) { }
return code is: int(-1073741819)
raw output is: string(0) ""
Output is: array(0) { }
return code is: int(0)
raw output is: string(0) ""
Output is: int(0)
return code is:
raw output is: NULL
Output is: int(0)
return code is:
raw output is: NULL