2

I call a Java function using PHP. The code is:

exec('pushd d:\xampp\htdocs\file_excecute\class & java Autoingestion username password id   Sales Daily Summary 20120902',$output,$return);

This code worked on a Windows machine but it is not working on a Linux server. The code is:

exec('pushd \var\www\domainname.com\itune_report\class & java Autoingestion username password id Sales Weekly Summary 20120901',$output,$return);
Chris
  • 44,602
  • 16
  • 137
  • 156
deepu sankar
  • 4,335
  • 3
  • 26
  • 37
  • 3
    Linux uses forward slashes to specify path components. Did you try replacing your back slashes with forward slashes? – mjgpy3 Sep 04 '12 at 12:28

3 Answers3

0

There are (perhaps insurmountable) difficulties when trying to execute sudo commands from a PHP script and from an external script called by PHP on SELinux enabled machines.

Make sure you use Linux directory path in your command

Linux won't let apache change the group id of the process by default.

You may need to use another solution, like make the PHP script deposit a file in a directory which is monitored by cron or inotify and which will call another script with root privileges.

Shail
  • 1,565
  • 11
  • 24
0

Obviously it does not work on Linux. Command pushd is defined in windows shell only. The path on linux must use forward and not back slashe as separator.

AlexR
  • 114,158
  • 16
  • 130
  • 208
0

You are using the wrong kind of slash as a field separator, but that may not be your only problem.

The output of the command appears in $output, since you use the exec(command, output, return) form.

However, this only gives you stdout. The shell will send error messages to stderr.

Unfortunately there isn't a version of exec() that reads stderr.

You can merge both outputs to $output by adding 2>&1 at the end of your shell command:

exec("mycommand 2>&1", $output, $return);

Look at $output, and you will either find the output of your successful command or error messages which you can use to work out why it didn't work.

If you want to write something more rigorous that treats stdout and stderr separately, you'll need to use proc_open() instead: PHP StdErr after Exec()

Community
  • 1
  • 1
slim
  • 40,215
  • 13
  • 94
  • 127