Okay, the documentation online at www.php.net/manual say that exec() will
run a system command and return the unix integer result code. passthru()
will do the same thing but echo the output of the command to the screen.
Typically, I like to use passthru() for development so I can better track
bugs, and then replace passthru() calls with either system() or exec().
Nik
-----Original Message-----
From: arun [mailto:arun@l...]
Sent: Thursday, December 27, 2001 6:21 AM
To: professional php
Subject: [pro_php] Still a problem while calling a script file using PHP
hi
thanks for the reply.
As you said i had only two commands in the script file
pwd,ls -laF. But still the output is 127 with no text printed to the screen.
when i tried seperately through 'passthru()' i am able to get the output.
testscript.sh
--------------
pwd
ls -laF
phpfile.php
--------------
<?
passthru("testscript.sh", $result);
echo $result;
?>
Output:
***************************
127
***************************
regards
arun
----- Original Message -----
From: "Nikolai Devereaux" <yomama@u...>
To: "professional php" <pro_php@p...>
Sent: Wednesday, December 26, 2001 11:22 PM
Subject: [pro_php] RE: hi
> ---
> Need a present for your favorite programmer?
> E-Documents from Amazon.com at http://p2p.wrox.com/edocs.asp
> ---
>
> Hi Arun,
>
> It looks to me like the passthru() function is working perfectly. The
thing
> is, you're not quite using the function correctly, and your script and
> filesystem are to blame for things not working the way you expect.
>
> The $result variable you're using is the integer return code. It's not
any
> text output from running your script.
>
> Your paths are more than likely screwed up. Try adding an "ls -laF"
and/or
> a "pwd" at the top of your script. Better yet, try just passing "ls -laF"
> and/or "pwd" to passthru(). Does test.c even exist in that dir? Does
your
> script?
>
> Chances are, one of them doesn't exist in the directory you're copying
from.
> And if it does, then maybe your web server user doesn't have write access
to
> the directory you're copying it to.
>
> If your script works for you on the command line, that's all well and
> good... but what user are you running it as? Have you tried logging into
> your system as the webserver user and running the script?
>
> Again, you should really try to paint the problem into a corner. If
> passthru() works on some commands, there's no reason why it shouldn't work
> on all. That your command is a script shouldn't make a difference.
>
> Find out what the problems are with your script.
>
> Nik
>
>
> -----Original Message-----
> From: arun [mailto:arun@l...]
> Sent: Wednesday, December 26, 2001 3:06 AM
> To: professional php
> Subject: [pro_php] hi
>
>
> ---
> Need a present for your favorite programmer?
> E-Documents from Amazon.com at http://p2p.wrox.com/edocs.asp
> ---
> hi,
> thanks for the reply.
> I tried as you said but it is not working.
> I have 3 files
> 1)copy.php // php file.
> 2)testscript.sh // Script file
> 3) test.c // the file to be copied to another directory.
> OS -> Linux
>
> copy.php
> -----------
> passthru('testscript.sh', $result);
> echo "Result ".$result
> Note : Also i tried with echo()
> **************************************
> testscript.sh
> ---------------
> cp test.c /etc // copy the file test.c to the folder etc.
>
> **************************************
> test.c
> -------
>
> some dummy text.
>
> ***************************************
> Output i got is -> Result 127
> ***************************************
> Also if the command (cp test.c /etc) is directly given it is not
accepting.
>
> But for "date" or "who" commands it is printing the output.
> I absorbed that if there is a space in the command it is not accepting.
>
> Note: I will be having more than one command in the script file.
> can you help?
>
> regards
> arun
>
>
> ----- Original Message -----
> From: "Nikolai Devereaux" <yomama@u...>
> To: "professional php" <pro_php@p...>
> Sent: Wednesday, December 26, 2001 2:23 PM
> Subject: [pro_php] RE: can we call a batch file from PHP?
>
>
> > ---
> > Need a present for your favorite programmer?
> > E-Documents from Amazon.com at http://p2p.wrox.com/edocs.asp
> > ---
> >
> > Well, if your script works from the command prompt, then it should work
> with
> > system(), passthru(), and exec(). I'd recommend doing this:
> >
> > <pre>
> >
> > <?php
> > passthru("your script filename here");
> > ?>
> > </pre>
> >
> >
> > That will show you the output of attempting to run the script from
within
> > PHP. Odds are that your script is executing, but isn't running in the
> > working dir that you expect.
> >
> > Good luck
> >
> > nik
> >
> >
> > -----Original Message-----
> > From: arun [mailto:arun@l...]
> > Sent: Tuesday, December 25, 2001 10:02 PM
> > To: professional php
> > Cc: aalang@r...
> > Subject: [pro_php] can we call a batch file from PHP?
> >
> >
> > ---
> > Need a present for your favorite programmer?
> > E-Documents from Amazon.com at http://p2p.wrox.com/edocs.asp
> > ---
> > hi
> > thanks for the reply.
> > Using the exec() command i am able to call a single command.
> > I have 4 commands for executing, so i created a script file and tried to
> > pass it to exec() function but it is not executing.
> > How can a script file be executed?? is there any seperate function for
> that.
> >
> > regards
> > arun
> > ----- Original Message -----
> > From: "Adam Lang" <aalang@r...>
> > To: "professional php" <pro_php@p...>
> > Sent: Monday, December 24, 2001 7:15 PM
> > Subject: [pro_php] Re: can we call a batch file from PHP?
> >
> >
> > > ---
> > > Need a present for your favorite programmer?
> > > E-Documents from Amazon.com at http://p2p.wrox.com/edocs.asp
> > > ---
> > > yes. use the exec() function
> > >
> > > Adam Lang
> > > Systems Engineer
> > > Rutgers Casualty Insurance Company
> > > http://www.rutgersinsurance.com
> > > ----- Original Message -----
> > > From: "arunm" <arun@l...>
> > > To: "professional php" <pro_php@p...>
> > > Sent: Monday, December 24, 2001 12:14 PM
> > > Subject: [pro_php] can we call a batch file from PHP?
> > >
> > >
> > > > ---
> > > > Need a present for your favorite programmer?
> > > > E-Documents from Amazon.com at http://p2p.wrox.com/edocs.asp
> > > > ---
> > > > hi all,
> > > > Can a batch file be called from PHP code?
> > > >
> $subst('Email.Unsub').
> > > >
> > >
> > >
> > >
> > >
$subst('Email.Unsub').
> > >
> >
> >
> >
> >
> >
>
>
>
>
>