raman Posted February 22, 2010 Share Posted February 22, 2010 I have embedded a shell script within a php script. The shell script runs correctly when I run it from the shell, however when I run it from the browser, only the first part of it runs while the second part does not. multiplets.o is a binary executable of c++ program. Can someone suggest? My machine is a Redhat eneterprise linux and php is 5.3.1 seqfile=$1; #first part cp $seqfile $seqfile.test; perl -pi -e "s/\t/\n/" $seqfile.test; perl -pi -e "s/>/>0/" $seqfile.test; perl fast_betteramcomph.pl $seqfile.test $seqfile.aac; #second part ./multiplets.o $seqfile.test $seqfile.mp > waste; cut -d ' ' -f 1-20 $seqfile.mp > $seqfile.mpc; perl -pi -e "s/$/ /" $seqfile.mpc; rm -rf $seqfile.mp; Quote Link to comment https://forums.phpfreaks.com/topic/192897-shell-script-not-running-in-php/ Share on other sites More sharing options...
jl5501 Posted February 22, 2010 Share Posted February 22, 2010 I would suggest making the paths to the files, full system path names. if they are not already. I would agree that it is odd that perl is finding the files in your first half, but I would certainly give that a try. It is certainly going to be the case that the default path setup is going to be different for the user running the shellscript from the shell command line, then it is for the user running apache. Quote Link to comment https://forums.phpfreaks.com/topic/192897-shell-script-not-running-in-php/#findComment-1015966 Share on other sites More sharing options...
raman Posted February 22, 2010 Author Share Posted February 22, 2010 I added the full system paths, but that did not help in any way. Quote Link to comment https://forums.phpfreaks.com/topic/192897-shell-script-not-running-in-php/#findComment-1015970 Share on other sites More sharing options...
jl5501 Posted February 22, 2010 Share Posted February 22, 2010 ok so 2 things. 1) I assume that your script does have the #!/bin/bash or whatever for the shell interpreter you wish to run. 2) Does your own executable have the appropriate execute permissions for the user running apache? Quote Link to comment https://forums.phpfreaks.com/topic/192897-shell-script-not-running-in-php/#findComment-1015973 Share on other sites More sharing options...
raman Posted February 22, 2010 Author Share Posted February 22, 2010 I have tried both the ways, with and without #!/bin/bash. It does not make any difference Also even when I set the permission as 777, it does not help. Quote Link to comment https://forums.phpfreaks.com/topic/192897-shell-script-not-running-in-php/#findComment-1015985 Share on other sites More sharing options...
jl5501 Posted February 22, 2010 Share Posted February 22, 2010 Then I would suggest that your executable is expecting something in its environment that it is not finding. I think you are going to have to put some extensive debug output in your executable, starting with a simple, 'yes I have started' Quote Link to comment https://forums.phpfreaks.com/topic/192897-shell-script-not-running-in-php/#findComment-1015991 Share on other sites More sharing options...
raman Posted February 22, 2010 Author Share Posted February 22, 2010 Yes you are right The problem is with this line, ./multiplets.o $seqfile.test $seqfile.mp > waste; when I put this as ./multiplets.o $seqfile.test $seqfile.mp , the script runs correctly, but the problem is that the useless information that I was directing to the file waste also appears on the browser, my output files is only $seqfile.mp, i need only that one. can you suggest what should be done about this ? Quote Link to comment https://forums.phpfreaks.com/topic/192897-shell-script-not-running-in-php/#findComment-1015993 Share on other sites More sharing options...
jl5501 Posted February 22, 2010 Share Posted February 22, 2010 Ok so is the waste output on stdout or stderr? If you do not want to keep this output I would suggest >/dev/null 2>&1 or >/tmp/waste 2>&1 if you do want to keep it Quote Link to comment https://forums.phpfreaks.com/topic/192897-shell-script-not-running-in-php/#findComment-1015995 Share on other sites More sharing options...
raman Posted February 22, 2010 Author Share Posted February 22, 2010 thank you, this helps. But I don't understand the meaning of /dev/null 2>&1 and /tmp/waste 2>&1 Quote Link to comment https://forums.phpfreaks.com/topic/192897-shell-script-not-running-in-php/#findComment-1015999 Share on other sites More sharing options...
jl5501 Posted February 22, 2010 Share Posted February 22, 2010 With any command that runs, there are 2 output streams, stdout and stderr. > redirects stdout as you have done 2> redirects stderr >2&1 says redirect stderr to same place as stdout Quote Link to comment https://forums.phpfreaks.com/topic/192897-shell-script-not-running-in-php/#findComment-1016013 Share on other sites More sharing options...
raman Posted February 22, 2010 Author Share Posted February 22, 2010 with stderr, I understand that it means the error messages. However, there is no error as such in this case. I don't understand why it works for me. Quote Link to comment https://forums.phpfreaks.com/topic/192897-shell-script-not-running-in-php/#findComment-1016014 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.