I have to execute an executable in linux that change a file and write another one.
I have tried with this comands:

exec("program");

system("program");

passthru("program");

The program works becouse it generate the new file but the new file have size 0!

Some help?
Thanx in advance

    Sounds like it could be a problem in the program you're executing. Does it run correctly if you execute it at the command line under the "nobody" user from the directory in which your script runs it?

      Yes, it runs ok if executed in shell linux.
      It create the new file with an amount of size different by zero.
      Ok...more infos.....

      exec("/usr/bin/antiword document/1.doc > document/1.txt");

      It convert the doc file to txt.It works in shell mode, not in php web page.
      The file 1.doc have nobody permission.

        try

        echo(shell_exec("/usr/bin/antiword document/1.doc 1>document/1.txt 2>error"));
        

        1> places stdout into the file after
        2> places stderr into the file after.
        Using shell_exec any data returned to php will be returned by shell_exec as a string echo will then output this string to the browser. There should be no output as both stdout(1) and stderr(2) are being handled unless there is a permissions failure on the stderr redirect.

        HTH
        Bubble

          Originally posted by bubblenut
          try

          echo(shell_exec("/usr/bin/antiword document/1.doc 1>document/1.txt 2>error"));
          

          The program is "antiword" the path to this file is /usr/bin
          It takes two argument file1 and file2 (the file to create)

          The source file is in "document/1.doc"
          The destination file i want to create is in "document/2.txt"

          The php code you have suggested me don't otput nothing.
          Why you write "1>document/1.txt 2>error"?

          The antiword program want the command arguments like "file1 >file2"

            Your script is not taking two arguments it's taking one document/1.doc and then it's outputing data to stdout which is being redirected with > to document/1.txt. Writting 1> is the same as > just explicitly saying that stdout should be used rather than stderr or any other output. Did it create a file called error? Is there anything in that file?

              Thanx for 1> suggest , well it create always the 1.txt with size 0 and no error file.Don' have no idea of what can be.
              If it doesn't create the error file seems like the program make his work.........don't know if it's a php related problem?
              It doesn't let to execute a program that write on hd?

                What are the permissions on the /usr/bin/antiword file? Can you make them less restrictive?

                  9 months later

                  Hi, sorry for bumping this old thread - but it was the youngest of the handful of old, unresolved threads I found on this subject 🙂

                  I have exactly the same problem - using PHP to handle a file upload, and if it's a Word doc I need to run it through antiword to get the text out.

                  Run from the command line antiword either dumps the plain text out to the screen, or it can be piped (>) to another file. So it seems that antiword does work?

                  However, running the very same shell command via PHP's exec command produces the output file, but like others have said, it is empty (0 bytes).

                  I'm relieved to see that people who have properly compiled and installed antiword on their systems have the same problem, because I just copied an executable onto mine - I don't have rights to compile and install new apps. I had thought that was likely to the the problem.

                  So does anyone have any ideas? Did anyone solve their problem with antiword?

                  I've also tried putting the antiword command in a shell script and calling that instead - again it works from the command line, but fails from PHP.

                  Also note - on my set up I'm also handling PDFs with the app pdftotext. I have that exe in the same directory as antiword - same permissions etc, reads and writes to same dir - and that works when called with exec()!!!
                  The only real diff between how the two work is that pdftotext allows you to specify a destination file, whereas with antiword you have to pipe the output.

                  Could the > be to blame here?

                  I really need to get this working by next week - so would really appreciate any help!

                    10 days later

                    I have been having the same problem. I have also noticed that you don't even need a vaild source file for antiword to create a blank file. The php command:

                    exec('/usr/local/bin/antiword file.doc > file.txt');

                    will always create a blank 'file.txt' (0kb) even if file.doc doesn't exist.

                    Did you come up with a solution to this by any chance?

                      no I never did get it working.

                      Instead, my plan is to write a shell script to call it (and pdftotext) run from crontab. I've tested the principal of it and antiword does work when called in that way. It just means that my docs won't be indexed the instant they are uploaded - the users will have to wait until the next crontab calls the script.

                        I contacted Matthew McClintock whose php antiword script seems to work ( link to script). He suggested putting the following line in all your php scripts that access antiword:

                        putenv("ANTIWORDHOME=/usr/local/.antiword");

                        Just replace '/usr/local' with your antiword install path and it seems to work.

                          wow that did the trick first try! Thanks very much, you saved me the bother of writing that cron script 🙂

                            Have you been able to get antiword to extract header and footers from the word documents? I can't seem to get it to work.

                              I haven't tested it that far - I was just happy that it got any text out of the Doc at all, which is good enough for my simple needs.

                                Write a Reply...