Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

exec() function, cmd, background printing

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

exec() function, cmd, background printing

Postby lukasg » Thu Jul 18, 2013 9:43 pm

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.
lukasg
New php-forum User
New php-forum User
 
Posts: 14
Joined: Thu Jul 18, 2013 9:39 pm

Re: exec() function, cmd, background printing

Postby johnj » Fri Jul 19, 2013 5:14 am

try using double slashes

Code: Select all
exec("C:\\Program Files (x86)\\Foxit Software\\Foxit Reader\\Foxit Reader.exe C:\\test.pdf")
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: exec() function, cmd, background printing

Postby lukasg » Sat Jul 20, 2013 10:27 am

i get:

It doesn't work

but when i try:

exec('"C:\\Program Files (x86)\\Foxit Software\\Foxit Reader\\Foxit Reader.exe" C:\\test.pdf')

i get same effect:

Image
lukasg
New php-forum User
New php-forum User
 
Posts: 14
Joined: Thu Jul 18, 2013 9:39 pm

Re: exec() function, cmd, background printing

Postby johnj » Sun Jul 21, 2013 9:29 pm

Please make sure that this command C:\\Program Files (x86)\\Foxit Software\\Foxit Reader\\Foxit Reader.exe works from command line.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: exec() function, cmd, background printing

Postby lukasg » Mon Jul 22, 2013 12:51 am

yes, it does

thats my *.bat

@ECHO OFF
"C:\\Program Files (x86)\\Foxit Software\\Foxit Reader\\Foxit Reader.exe" /p C:\\test.pdf
EXIT
lukasg
New php-forum User
New php-forum User
 
Posts: 14
Joined: Thu Jul 18, 2013 9:39 pm

Re: exec() function, cmd, background printing

Postby johnj » Tue Jul 23, 2013 8:54 pm

No,not a batch file. You need to execute that command "alone"
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: exec() function, cmd, background printing

Postby lukasg » Tue Jul 23, 2013 9:58 pm

It's, working alone

Image
lukasg
New php-forum User
New php-forum User
 
Posts: 14
Joined: Thu Jul 18, 2013 9:39 pm

Re: exec() function, cmd, background printing

Postby johnj » Wed Jul 24, 2013 8:14 am

try this: put the entire string of command for exec in double quotes. You will have to escape any other double quotes in between the full command. Right now you are using a single quote.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: exec() function, cmd, background printing

Postby johnj » Wed Jul 24, 2013 8:20 am

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.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: exec() function, cmd, background printing

Postby lukasg » Thu Jul 25, 2013 12:19 am

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.
lukasg
New php-forum User
New php-forum User
 
Posts: 14
Joined: Thu Jul 18, 2013 9:39 pm

Re: exec() function, cmd, background printing

Postby johnj » Thu Jul 25, 2013 8:43 am

try this

Code: Select all
exec("C:\\Program Files (x86)\\Foxit Software\\Foxit Reader\\Foxit Reader.exe /p C:\\test.pdf ")


Also - when you run foxitreader.exe from command line does it open up a window. what does foxitreader.exe do?
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: exec() function, cmd, background printing

Postby lukasg » Thu Jul 25, 2013 11:39 pm

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...
lukasg
New php-forum User
New php-forum User
 
Posts: 14
Joined: Thu Jul 18, 2013 9:39 pm

Re: exec() function, cmd, background printing

Postby johnj » Fri Jul 26, 2013 8:03 am

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);
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: exec() function, cmd, background printing

Postby johnj » Fri Jul 26, 2013 8:17 am

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);
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: exec() function, cmd, background printing

Postby lukasg » Fri Jul 26, 2013 12:33 pm

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."
lukasg
New php-forum User
New php-forum User
 
Posts: 14
Joined: Thu Jul 18, 2013 9:39 pm

Re: exec() function, cmd, background printing

Postby johnj » Fri Jul 26, 2013 8:34 pm

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:
Code: Select all
07/18/13  11:52 AM    <DIR>          PROGRA~1     Program Files
02/24/13  11:45 AM    <DIR>                             tmp


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.
Attachments
dir_snap.jpg
dir_snap.jpg (13.33 KiB) Viewed 1179 times
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: exec() function, cmd, background printing

Postby lukasg » Sat Jul 27, 2013 4:29 am

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
lukasg
New php-forum User
New php-forum User
 
Posts: 14
Joined: Thu Jul 18, 2013 9:39 pm

Re: exec() function, cmd, background printing

Postby johnj » Sat Jul 27, 2013 8:50 am

did you check if test.pdf was created in C:\> ?

now, try this:
Code: Select all
$rawoutput = exec("C:\\PROGRA~2\\FOXITS~1\\FOXITR~1\\FOXITR~1.exe /p C:\\test.pdf", $output,$retcode );


or even this
Code: Select all
$rawoutput = exec("C:\PROGRA~2\FOXITS~1\FOXITR~1\FOXITR~1.exe /p C:\test.pdf", $output,$retcode );


I can give you only suggestions as I am not able to try this on my side.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: exec() function, cmd, background printing

Postby lukasg » Sat Jul 27, 2013 12:36 pm

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...
lukasg
New php-forum User
New php-forum User
 
Posts: 14
Joined: Thu Jul 18, 2013 9:39 pm

Re: exec() function, cmd, background printing

Postby johnj » Sun Jul 28, 2013 4:46 am

test.pdf exists on C: drive, so I am not sure what you trying to do.

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");
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: exec() function, cmd, background printing

Postby lukasg » Sun Jul 28, 2013 5:48 am

All i want is to force my printer to print test.pdf using exec() php function.

passthru() ends up with nothing, how can i debug passthru ?
lukasg
New php-forum User
New php-forum User
 
Posts: 14
Joined: Thu Jul 18, 2013 9:39 pm

Re: exec() function, cmd, background printing

Postby johnj » Sun Jul 28, 2013 7:15 am

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'");
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: exec() function, cmd, background printing

Postby lukasg » Mon Jul 29, 2013 12:23 am

No error, no warnings, no nothing, print dialog window doesnt appear, print wont print...
lukasg
New php-forum User
New php-forum User
 
Posts: 14
Joined: Thu Jul 18, 2013 9:39 pm

Re: exec() function, cmd, background printing

Postby johnj » Mon Jul 29, 2013 8:47 am

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);
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: exec() function, cmd, background printing

Postby lukasg » Mon Jul 29, 2013 10:48 pm

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
lukasg
New php-forum User
New php-forum User
 
Posts: 14
Joined: Thu Jul 18, 2013 9:39 pm

Next

Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 5 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron