#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    32
    Rep Power
    5

    Execute a command from php file


    hello,
    I'm trying to execute an external command from my php project but I'm not able to open, for example, winword nor AcroRd32:
    system('AcroRd32.exe');
    system('winword.exe');
    system('start AcroRd32.exe');
    system('start 'winword.exe');

    In "task manager" I see the task started, but nothing appened....

    If I try by "os prompt" I have no problem...

    I've tryed also using "exec" and "shell_exec": the same result

    please help me, thank you
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,496
    Rep Power
    594
    Whether you are running Apache or IIS under windows, they are normally run as a service. There is no console associated with the service for those applications to open. I don't know about IIS but you can start Apache in foreground from a command prompt in which case it may work.

    Of course the real question is why would you want to run an interactive command from a server in the first place?
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    32
    Rep Power
    5
    thanks for your reply
    In fact I need to send to a printer a pdf file from my PHP project

    I tryed:
    system('AcroRd32.exe" /p /h "myfile"');

    but it didn't works, so I made a step back tring only:
    system('AcroRd32.exe');

    my real problem is:
    how can I send directly to a network printer a pdf file?

    I'm becoming crazy....
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    32
    Rep Power
    5
    ok, I've found this way, maybe better, but I need an help:

    I can use the command 'lpr':

    lpr -S 192.168.10.15 -P 192.168.10.15 myfile.pdf

    no problem with txt file but if I try to print a pdf file, it prints wrong (particular and special characters....)

    I see that lpr command has an option "-o" to indicate the file type....
    do you know if it is the right way to print my pdf?

    thanks
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,496
    Rep Power
    594
    You're on the right track but you need to find a command line printer that supports PDF. You might look at GhostScript or Foxit Reader.

    Have you considered the possibility that letting clients print on your server could result in someone flooding it with printing? You will need to put some kind of security in place.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    32
    Rep Power
    5
    thank you

    can you give me some infos about these software?
    are they free?
    how can i use them?

    thank you very much
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,496
    Rep Power
    594
    Google them. GhostScript is free (open source) but I'm not sure about Foxit Reader.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    32
    Rep Power
    5
    thanks,
    I'm trying GhostScript but I need some help

    I work on windows and I need to print myfile.pdf on my printer laserjet named (in printer control panel) "my HP printer"

    this command doesn't work but I do not understand why, can you help me?

    gswin32c.exe -sDEVICE=laserjet -sOutputFile="%printer%my HP printer" myfile.pdf

    thank you again
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,496
    Rep Power
    594
    According to the documentation you must add gs\bin and gs\lib to the PATH, where gs is the top-level Ghostscript directory. Presumably you have that configured correctly from the installer but you should check with 'echo %PATH%'. For PDF files you also need to include the switch '-dPrinted'. The OutputFile variable is for printing to a file not a real printer. Use the '-h' switch to find your printer device and that is all you should specify.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    32
    Rep Power
    5
    I've modified my comand in this way:

    gswin32c.exe -sDEVICE=laserjet -dPrinted myfile.pdf

    no error but it doesn't work

    using -h option, I've seen that there are a lot of printer devices...how can I choose mine?

    maybe my problem is here...

    ...
    epson epsonc epswrite ibmpro ijs jetp3852 jpeg jpegcmyk jpeggray laserjet lbp8 lj250 ljet2p ljet3 ljet3d ljet4 ljet4d ljetplus
    ...
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,496
    Rep Power
    594
    What is your printer?
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    32
    Rep Power
    5
    this is the name I see in the printers list:
    KONICA MINOLTA 362/282/222 PCL
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,496
    Rep Power
    594
    I see the problem, that is a postscript printer. I forgot you are using Windows. You need the 'mswinpr2' device. However, I suggest you use 'gsprint' instead.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    32
    Rep Power
    5
    thanks, great!!!

    it works!

IMN logo majestic logo threadwatch logo seochat tools logo