0

I'm trying to use a SWATH (http://www.cs.cmu.edu/~paisarn/software.html) to work on my project. Basically the program will break down the sentence into set of words. I have everything installed and and try to run the command through the command prompt (Terminal on Mac).

I ran a command

swath -u u -m long < in_OdwJYw.txt > test.txt

The program works just fine and came out with the correct output test.txt with break down words

So I implement the code into my PHP file. I use this method

exec("swath -u u -m long < in_OdwJYw.txt > test.txt");

No error shown "test.txt" file was created but nothing inside (0 bytes)

My question is why the command works with running through the prompt and why I not working with exec() system() or shell_exec().

Thanks!

Ittikorn S.
  • 288
  • 4
  • 20

1 Answers1

2

EDIT : Original post was edit by OP. Code snippet was:

exec("swath -b "|" -u u -m long < in_OdwJYw.txt > test.txt");

You have to escape your command-string. Something like that should help.

exec("swath -b \"|\" -u u -m long < in_OdwJYw.txt > test.txt");

In detail your string will be cut at exec("swath -b \" this place. The pipe is outside your command string. I think the rest of your command will be ignored and only the first part will run in the exec.

To include the rest you have to escape your special chars, in this case your ". When you use an editor with syntax highlighting you will see it much better.

Here you have a simple example in php esaping.

Often it is useful to print_r() the output from the exec() command. So you can see what happened.

Sentencio
  • 230
  • 1
  • 13
  • Okay I did some modification with the code changed it to 'swath -m long < in_OdwJYw.txt > test.txt' still no chance of working returning the same blank test.txt but fine while running through the prompt – Ittikorn S. Nov 21 '12 at 07:24
  • Did you check the output of the `exec()` command? It could be a problem with user rights – Sentencio Nov 21 '12 at 07:29
  • I tried `print_r(exec("swath -m long < in_OdwJYw.txt > test.txt"));` it returns nothing. I even try to put the sudo infront of swath still same result. Is it possible that there is something I need to config (enable/disable) in php.ini? – Ittikorn S. Nov 21 '12 at 07:34
  • Please check [exec()](http://de1.php.net/manual/de/function.exec.php). There you can see how the exec command works. `string exec ( string $command [, array $output [, int $return_var ]] )` You need a second param which is an array. – Sentencio Nov 21 '12 at 07:41