Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_php thread: PHP Exterrnal Program Functions


Message #1 by cullan.crothers@w... on Wed, 5 Dec 2001 21:57:26
This is a multi-part message in MIME format.

--Boundary_(ID_sA44YYM2YFqt7qL3rRYDwg)
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 7bit

RE: [pro_php] RE: PHP Exterrnal Program FunctionsDear David:

Thank you! I did finally figure that out and that is when I got it fixed!

Cullan
  -----Original Message-----
  From: David Cameron [mailto:dcameron@i...]
  Sent: Sunday, December 09, 2001 8:38 PM
  To: professional php
  Subject: [pro_php] RE: PHP Exterrnal Program Functions


  Just for completeness: IIS runs by default under the IUSR_<your machine
name> account. Eg if you machine name is server then the account IIS runs
under would be IUSER_server. If you need to add permissons add them to this
account. This explains why things seem to run fine when you test it, but not
ehn it is run in the page.

  regards
  David Cameron
  nOw.b2b
  dcameron@i...

  -----Original Message-----
  From: Nikolai Devereaux [mailto:yomama@u...]
  Sent: Saturday, 8 December 2001 8:55 AM
  To: professional php
  Subject: [pro_php] RE: PHP Exterrnal Program Functions




  Congrats, glad to hear it's all working out!  I'm glad to have helped.

  Nik

  -----Original Message-----
  From: Cullan Crothers [mailto:cullan.crothers@w...]
  Sent: Friday, December 07, 2001 2:51 PM
  To: professional php
  Subject: [pro_php] RE: PHP Exterrnal Program Functions



  Dear Nik:

  I GOT IT!!!! I HAD TO CHANGE SOME PERMISSIONS IN THE WEB DIRECTORY IN IIS.
  Now the file runs the batch file and copies the file like it should on the
  web server! Thank you so much for sticking with me on this. You did well.

  Cullan Crothers

  -----Original Message-----
  From: Nikolai Devereaux [mailto:yomama@u...]
  Sent: Friday, December 07, 2001 3:53 PM
  To: professional php
  Subject: [pro_php] RE: PHP Exterrnal Program Functions




  If you can't write files, it's probably that your webserver isn't allowed
to
  write or modify files, or you're out of disk space.

  The last case is not likely.  I think there's a web services configuration
  tool under Administrative Tools that will allow you to set permissions on
a
  per-directory basis for IIS.

  nik

  -----Original Message-----
  From: Cullan Crothers [mailto:cullan.crothers@w...]
  Sent: Friday, December 07, 2001 12:49 PM
  To: professional php
  Subject: [pro_php] RE: PHP Exterrnal Program Functions



  Dear Nik:

  That was a great suggestion! When I edit the batch file to just "dir". The
  PHP file returns in the browser the command prompt and the entire worrking
  (wwwroot) directory. If I edit the batch file to just echo some lines, it
  will return those also in the browser, but when I try to get it to do
  anything with a file (copy, rename, etc.) It will not work. What could
this
  be? So, it will run programs as long as they don't change any files.

  Cullan

  -----Original Message-----
  From: Nikolai Devereaux [mailto:yomama@u...]
  Sent: Friday, December 07, 2001 11:59 AM
  To: professional php
  Subject: [pro_php] RE: PHP Exterrnal Program Functions




  Does IIS set up to run as a specific user (similar to how Apache runs
under
  linux)?  If so, IIS might not have write permissions in that directory.

  Still, it seems strange that it wouldn't run correctly.

  Try changing the contents of your batch file to simply "dir" and see what
  output you get.

  wish I could be of more help,

  nik

  -----Original Message-----
  From: Cullan Crothers [mailto:cullan.crothers@w...]
  Sent: Friday, December 07, 2001 9:33 AM
  To: professional php
  Subject: [pro_php] RE: PHP Exterrnal Program Functions



  Dear Adam:

  It prints out as one line in the browser. LIke So --->>>
  c:\inetpub\wwwroot>copy c:\inetpub\wwwroot\testprog1.txt
  c:\inetpub\wwwroot\testprog2.txt
  ----->>>>>>>>

  I think my email may have broken it up into two lines.

  Cullan

  -----Original Message-----
  From: Adam Lang [mailto:aalang@r...]
  Sent: Friday, December 07, 2001 10:05 AM
  To: professional php
  Subject: [pro_php] RE: PHP Exterrnal Program Functions



  AH!!!!

  See what is happening?   It is breaking it into two lines, not a single
  command!

  Adam Lang
  Systems Engineer
  Rutgers Casualty Insurance Company
  http://www.rutgersinsurance.com
  ----- Original Message -----
  From: "Cullan Crothers" <cullan.crothers@w...>
  To: "professional php" <pro_php@p...>
  Sent: Friday, December 07, 2001 11:00 AM
  Subject: [pro_php] RE: PHP Exterrnal Program Functions



  > Dear Nik:
  >
  > When I run the PHP file with this code in it from my browser
  > (IE5.5)------>>>>>>
  >
  > <HTML>
  > <BODY>
  > NEW FILE.
  >
  > <?php
  > $cmd = "c:\\inetpub\\wwwroot\\testfile.bat";
  > system("cmd /c " . $cmd);
  > ?>
  >
  > </BODY>
  > </HTML>
  > ------------------>>>>>
  >
  > I get this result in the browser window--------->>>>>>
  >
  > c:\inetpub\wwwroot>copy c:\inetpub\wwwroot\testprog1.txt
  > c:\inetpub\wwwroot\testprog2.txt
  >
  > ---------------------->>>>>>This reflects the entire contents of the
batch
  > file that it is supposed to run.
  >
  > Still no file copied to the directory though.
  >
  > It does run and complete the commands when not run in the browser.
  > Any suggestions from this?
  >
  > Cullan
  >
  >
  > -----Original Message-----
  > From: Nikolai Devereaux [mailto:yomama@u...]
  > Sent: Thursday, December 06, 2001 5:19 PM
  > To: professional php
  > Subject: [pro_php] RE: PHP Exterrnal Program Functions
  >
  >
  >
  > You should!  try reading these:
  >
  > http://localhost/iishelp/iis/htm/adminsamples/default.htm
  > http://localhost/iishelp/iis/htm/adminsamples/adsutil.htm
  >
  > (from http://support.microsoft.com/default.aspx?scid=kb;EN-US;q240225)
  >
  > gl
  >
  > -----Original Message-----
  > From: Cullan Crothers [mailto:cullan.crothers@w...]
  > Sent: Thursday, December 06, 2001 3:09 PM
  > To: professional php
  > Subject: [pro_php] RE: PHP Exterrnal Program Functions
  >
  >
  > Dear Adam:
  >
  > I don't have that directory or an executable named adsutils anything on
my
  > PC in windows 2000 Server.
  >
  > Cullan
  >
  > -----Original Message-----
  > From: Adam Lang [mailto:aalang@r...]
  > Sent: Thursday, December 06, 2001 2:43 PM
  > To: professional php
  > Subject: [pro_php] RE: PHP Exterrnal Program Functions
  >
  >
  > >From the PHP website in the annotation:
  >
  > There is a problem by the function exec() and PHP4 under Windows. If you
  > don't get the results line(s) it is possible, that the process hasn't an
  > own console. For IIS 4.0 for example you can switch, that each process
get
  > an own console, with following:
  >
  > 1. open a DOS-Box and go to the directory
  > "..\winnt\system32\inetsrv\adminsamples"
  >
  > 2. give the following command
  > "adsutil set w3svc/CreateCGIWithNewConsole 1"
  >
  > Adam Lang
  > Systems Engineer
  > Rutgers Casualty Insurance Company
  > http://www.rutgersinsurance.com
  > ----- Original Message -----
  > From: "Cullan Crothers" <cullan.crothers@w...>
  > To: "professional php" <pro_php@p...>
  > Sent: Thursday, December 06, 2001 3:12 PM
  > Subject: [pro_php] RE: PHP Exterrnal Program Functions
  >
  >
  > > Dear Nik:
  > >
  > > The testfile.bat file contains one line --->>>>
  > >
  > > copy c:\inetpub\wwwroot\testprog1.txt c:\inetpub\wwwroot\testprog2.txt
  > >
  > > ----->>>>>>>
  > >
  > > That is all that's in there.
  > >
  > > Cullan
  > >
  > > -----Original Message-----
  > > From: Nikolai Devereaux [mailto:yomama@u...]
  > > Sent: Thursday, December 06, 2001 1:03 PM
  > > To: professional php
  > > Subject: [pro_php] RE: PHP Exterrnal Program Functions
  > >
  > >
  > >
  > > What's the contents of "testfile.bat"?
  > >
  > > -----Original Message-----
  > > From: Cullan Crothers [mailto:cullan.crothers@w...]
  > > Sent: Thursday, December 06, 2001 7:32 AM
  > > To: professional php
  > > Subject: [pro_php] RE: PHP Exterrnal Program Functions
  > >
  > >
  > > Dear Nik:
  > >
  > > Thanks for your help. I still can't get any progress. I run the PHP
file
  > > with both codes separately (with and without cmd /c) and get no return
  > data
  > > and the testfile.bat program does not succeed. No errors are returned.
  If
  > > you have any more ideas I would love to know them. I looked through
the
  > PHP
  > > Manual and tried some things there, but I don't know if those
  suggestions
  > > even worked for the people who sent them into it.
  > > The program still runs fine from DOS.
  > >
  > > Cullan
  > >
  > > -----Original Message-----
  > > From: Nikolai Devereaux [mailto:yomama@u...]
  > > Sent: Wednesday, December 05, 2001 5:11 PM
  > > To: professional php
  > > Subject: [pro_php] RE: PHP Exterrnal Program Functions
  > >
  > >
  > >
  > > According to http://www.php.net/manual/en/function.exec.php, your code
  > > should look like
  > >
  > >   exec("cmd /c c:\\inetpub\\wwwroot\\testfile.bat");
  > >
  > > Copy/paste this into a new file:
  > >
  > > <?php
  > >   $file = "c:\\inetpub\\wwwroot\\testfile.bat";
  > > ?>
  > > <HTML><HEAD><TITLE>testing system/exec</TITLE></HEAD>
  > > <BODY>
  > > <PRE>
  > > With cmd /c:
  > >
  > > <?php
  > >   system('cmd /c ' . $cmd);
  > > ?>
  > > <HR>
  > > Without:
  > >
  > > <?php
  > >   system($cmd);
  > > ?>
  > > </PRE>
  > > </BODY>
  > > </HTML>
  > >
  > >
  > > and you should see exactly what's being run/returned by the OS in
either

  > > case.
  > >
  > > -----Original Message-----
  > > From: Cullan Crothers [mailto:cullan.crothers@w...]
  > > Sent: Wednesday, December 05, 2001 3:04 PM
  > > To: professional php
  > > Subject: [pro_php] RE: PHP Exterrnal Program Functions
  > >
  > >
  > > Dear Nik:
  > >
  > > Thanks for the reply! My whole code looks like this. ------>>>
  > >
  > > <?php
  > >
  > > exec ("c:\\inetpub\\wwwroot\\testfile.bat");
  > >
  > > ?>
  > >
  > > ---------------->>>>>>>>.
  > > I am running windows 2000 server.
  > > It does not run the batch file still. The batch file runs fine in DOS.
  > Where
  > > would the cmd /c that you mentioned go in this code? I t is a real
  simple
  > > batch file that just copies a file to another file name with no
  > parameters.
  > >
  > > Cullan
  > >
  > > -----Original Message-----
  > > From: Nikolai Devereaux [mailto:yomama@u...]
  > > Sent: Wednesday, December 05, 2001 4:21 PM
  > > To: professional php
  > > Subject: [pro_php] RE: PHP Exterrnal Program Functions
  > >
  > >
  > >
  > > Also --
  > >
  > > make sure your batch file doesnt use dos env vars.  I wrote a batch
file
  > in
  > > a test php dir that simply does this:
  > >
  > > copy *.php %USERPROFILE%\Desktop
  > >
  > >
  > > Here's what I learned --
  > >
  > > This works fine when run from dos, in its directory.  However, PHP
  doesn't
  > > run the batch file from its own directory, so *.php doesn't match any
  > files.
  > > %USERPROFILE% completely disappears in the context of the exec call.
  > >
  > > Try playing with "system" instead of "exec" and see exactly what the
  batch
  > > file commands are called as and what their input is.
  > >
  > >
  > >
  > > -----Original Message-----
  > > From: cullan.crothers@w... [mailto:cullan.crothers@w...]
  > > Sent: Wednesday, December 05, 2001 9:57 PM
  > > To: professional php
  > > Subject: [pro_php] PHP Exterrnal Program Functions
  > >
  > >
  > > Dear P2P:
  > >
  > > I am trying to use the PHP external program function exec() to run a
  batch
  > > file. I cannot get it to run from PHP and wonder if I am not
configured
  to
  > > do so (Is there something in php.ini you have to do to make it ready
for
  > > this?). I simply enter the line into my code as such
  > > exec("c:\inetpub\wwwroot\testprogram");
  > > Then I run the PHP file and no error occurs, but the external program
  does
  > > not get run. The external program is a simple batch file that copies a
  > > file from one place to another. What could I be doing wrong here?
  > >
  > > Cullan Crothers
  > > cullan.crothers@w...
$subst('Email.Unsub').
  > >
  > >
$subst('Email.Unsub').
  > >
  > >
$subst('Email.Unsub').
  > >
  > >
$subst('Email.Unsub').
  > >
  > >
$subst('Email.Unsub').
  > >
  > >
$subst('Email.Unsub').
  > >
  > >
$subst('Email.Unsub').
  > >
  >
  >
  >
  >
  >
  >
  >
  >
  >
  >
  >


























  Return to Index