PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 12th, 2003, 06:05 AM
cuboctahedron cuboctahedron is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Netherlands
Posts: 440 cuboctahedron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 5 h 18 m
Reputation Power: 8
using system() to execute pkzip??

Hi,
I am trying to use pkzip to compress documents.
I am running a windows PC, so I am trying to execute a DOS command.

I have so far:
<?php
$pkzip="C:/Progra~1/Apache~1/Apache/readwr~1/pkzip.exe";
$pkzipdirectory="C:/Progra~1/Apache~1/Apache/readwr~1/";
$command=$pkzip." ".$pkzipdirectory."myzip.zip"." ".$pkzipdirectory."mydoc.doc";


system($command);
?>
The system() command doestn seem to do anything.
Neither does:
exec($command);
shell_exec($command);

In case I would echo the $command and copy the outputtext to the command prompt; it works fine, but how can I execute it from php?

kind regards
Patrick

Last edited by cuboctahedron : March 12th, 2003 at 06:09 AM.

Reply With Quote
  #2  
Old March 12th, 2003, 06:33 AM
podulator podulator is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 45 podulator User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 8 sec
Reputation Power: 9
hi,
i'm messing with this at the moment as well.
only seems to work with apache, but it looks like thats what you're using, so try path like c:\\path\\to\\pkzip instead of c:/path/to/zip

cheers
mat

Reply With Quote
  #3  
Old March 12th, 2003, 06:37 AM
cuboctahedron cuboctahedron is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Netherlands
Posts: 440 cuboctahedron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 5 h 18 m
Reputation Power: 8
I am running Apache with php4.2 on my windows machine.
The '/' also work on windows. I also tried the backslashed.

I am wondering; must I include a line to open the cmd box(command prompt box); bassically the script assumes that I am already runnig a cmb box

Reply With Quote
  #4  
Old March 12th, 2003, 06:41 AM
podulator podulator is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 45 podulator User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 8 sec
Reputation Power: 9
shouldn't have to as long as cmd.exe is in your path.
can't believe its not really.

maybe try a little test like this and see what you get back,
then you'll know if its a path problem.....

<?php

$test = shell_exec("ping 192.168.0.1");
echo $test;

?>

if that works then maybe add the location of zip to your systems path.

cheers
mat

Reply With Quote
  #5  
Old March 12th, 2003, 06:57 AM
cuboctahedron cuboctahedron is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Netherlands
Posts: 440 cuboctahedron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 5 h 18 m
Reputation Power: 8
The ping works ok!
I can do the standard commands alright.

If I type:
$test=shell_exec("C:/Progra~1/Apache~1/Apache/readwr~1/pkzip.exe C:/Progra~1/Apache~1/Apache/readwr~1/myzip.zip C:/Progra~1/Apache~1/Apache/readwr~1/mydoc.doc");
echo $test;

nothing happens
I tried:
1)using absolute directories (like above)
2) changing path=, to include the pkzip file (A dos version of pkzip)
3) changing to the 'long' directory notation (e.g progra~1 => program files)

HELP.., what am I doing wrong?

Patrick

Reply With Quote
  #6  
Old March 12th, 2003, 08:08 AM
cuboctahedron cuboctahedron is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Netherlands
Posts: 440 cuboctahedron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 5 h 18 m
Reputation Power: 8
Anyone please? I am using the default php.ini settings. Must I change something there?

Reply With Quote
  #7  
Old March 12th, 2003, 08:51 AM
podulator podulator is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 45 podulator User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 8 sec
Reputation Power: 9
talking of php.ini check safe_mode is off...

i guess 2 things to try,
1. stick pkzip and another file to zip at root of c drive so there's no problem with long / short path nanes

2. copy ping.exe to where pkzip is living and try and hit it there.

i ended up sticking my .exe at root of c drive while i'm working on it and its fine...

otherwise out of things to try

Reply With Quote
  #8  
Old March 12th, 2003, 09:07 AM
sankyu sankyu is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 38 sankyu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Executing commands in the shell from a PHP script only works when the program you are trying to execute resides in your system directory (windows 2000: c:\winnt\system32).
This is the reason why the ping command did work, yet your attempt to use pkzip didnt (even when you include the full patch to it).
A work around for this is to create a batch file which does what you want, or which takes variables from the PHP script, and then put this batch script in your system directory.
Execute the batch file from the PHP script, and it should work.
__________________
Windows 2000 SP4
Apache v2.0.44
PHP v4.3.1
MySQL v3.23.55

Reply With Quote
  #9  
Old March 12th, 2003, 09:37 AM
grebmil grebmil is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: WNY
Posts: 207 grebmil User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
sankyu is correct. See the last 2 user comments on this page of the manual.

Note: If safe mode is enabled you have to use shell_exec(), not the backtick operator used here. Either way, the batch files should work the same.
__________________
strrev ("grebmil")

Reply With Quote
  #10  
Old March 12th, 2003, 09:46 AM
sankyu sankyu is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 38 sankyu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Quote:
Originally posted by grebmil

Note: If safe mode is enabled you have to use shell_exec(), not the backtick operator used here


ah yes, an important detail I forgot to add, thank you.

Reply With Quote
  #11  
Old March 12th, 2003, 10:02 AM
cuboctahedron cuboctahedron is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Netherlands
Posts: 440 cuboctahedron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 5 h 18 m
Reputation Power: 8
I'm getting crazy.....
I cannot run pkzip (v2.04) for dos from a php file

I did everything you all said:.........
- I created a batchfile, in system32 directory, called run.bat
- I copied pkzip.exe into system32 directory

the batchfile has one single line:
___________________________
c:\windows\system32\pkzip.exe c:\windows\system32\test.zip c:\windows\system32\test.doc
___________________________

The batchfile work allright, regardless of path.

my php page has:
$test = shell_exec("run.bat");
echo $test;

the output (echo $test) is:
c:\program files\apache group\apache\htdocs\mywebsite>c:\windows\system32\pkzip.exe c:\windows\system32\test.zip c:\windows\system32\test.doc

Anyone 1 more last suggestion for me? (Does anyone have a working script otherwise for me using pkzip?)

kind regard
Patrick

Last edited by cuboctahedron : March 12th, 2003 at 10:13 AM.

Reply With Quote
  #12  
Old March 12th, 2003, 10:15 AM
sankyu sankyu is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 38 sankyu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Your syntax is wrong, it should look like this;
PHP Code:
 $test shell_exec("run.bat");
echo 
$test

and if you want to use the backtick operator:
PHP Code:
 $test = `run.bat`;
echo 
$test

either way, be sure to end the variable line with a ; which it seems you did not do.
Also, when using the backtip operator, take note of the fact that the backtick is not he same character as a single quote. The backtick is located to the left of the number 1, beneath your esc button

ps; please use the bb PHP tags when you post PHP code, this makes for easier reading, and syntax highlighting.

Reply With Quote
  #13  
Old March 12th, 2003, 10:17 AM
grebmil grebmil is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: WNY
Posts: 207 grebmil User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
You also need to specify the full path to run.bat and make sure that all the dirs and files refered to in your batch file are MS-DOS short names.

Reply With Quote
  #14  
Old March 12th, 2003, 10:55 AM
cuboctahedron cuboctahedron is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Netherlands
Posts: 440 cuboctahedron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 5 h 18 m
Reputation Power: 8
Sorry about the bad syntax, but they were 'copy-pasted' incomplete. I've corrected it

Guys, I really dont know it anymore; I tried rar.exe (instead of pkzip), but not working neither.

I mean I am not a newbie, or bad coder. I hope someone else dealt with this matter also. It really baffles me.

I don't know why I can only run the standard 'windows' commands like ping, dir,echo.... etc,(via batchfile or not) through PHP, but not an application like pkzip(for DOS).

Are there any other considerations I might have forgotten?

Reply With Quote
  #15  
Old March 12th, 2003, 11:00 AM
cuboctahedron cuboctahedron is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Netherlands
Posts: 440 cuboctahedron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 5 h 18 m
Reputation Power: 8
I might have a clue!?!?
e.g. I have a batchfile saying:
----------------------------------
echo this batchfile works
----------------------------------
running this with:
<?php
$test=shell_exec("run.bat ");
echo $test;
?>
echoos 'echo this batchfile works'

Shouldnt the 'echo' NOT be there in the echo $test? It's like it is just reading the line, instead of executing it.......

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > using system() to execute pkzip??


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
Stay green...Green IT