PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

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 July 4th, 2000, 06:33 AM
od od is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 21 od User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to od
Hello ppl,

I am going crazy.......

I have 1 variable lets call it

$1 = "/tmp/x.txt";


then i want to issue a unix system command like this:
for example:

system('/bin/cat /etc/passwd > $1');
------------------------------------------

The problem is that $1 becomes empty (no data) in my system() line. if i just type print $1; it returns correct value.

Anyone who has any clues whats wrong?

Best Regards
od


Reply With Quote
  #2  
Old July 4th, 2000, 09:10 AM
kaasgaard kaasgaard is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2000
Location: Aalborg, Denmark
Posts: 36 kaasgaard User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 14
Send a message via ICQ to kaasgaard
Hi

I'm not sure what you're trying to do, but you should try to check passThru(), exec(), escapeShellCmd()... the all handle the return statement slightky different.

But if you want to copy the contents of /etc/passwd to /tmp/x.txt you should use copy("/etc/passwd", "/tmp/x.txt").

If you want to read the contents you just use
fopen("/tmp/x.txt");
or a similar command.

Hope this helps you, otherwise try to state what you want to accomplish.

Regards

// Martin

Reply With Quote
  #3  
Old July 5th, 2000, 11:21 AM
od od is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 21 od User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to od
Hi....ok here is exactly what i want to do:

1. I have a html FORM with 2 fields
2. Each field has its own "name" which becomes a variable in the script.
3. I want to pass those variable values into the system(xxx) command i mentioned above.

Something like this:
<input type=text name=myusername>
<input type=text name=mypassword>

<?php
system('/usr/bin/adduser $myusername -p $mypassword');

?>

In my case $myusername and $mypassword are "not passed" to the system() line.
if i add print "$myusername, $mypassword"; above or under the system line its printed correctly.

Best regards
od

Reply With Quote
  #4  
Old July 5th, 2000, 12:28 PM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 17
Send a message via AIM to rod k
You need to change the single quotes to double quotes. PHP won't parse variables inside single quotes and will pass them as literals. i.e. this:

system('/usr/bin/adduser $myusername -p $mypassword');

should be:

system("/usr/bin/adduser $myusername -p $mypassword");

Reply With Quote
  #5  
Old July 6th, 2000, 01:25 AM
od od is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 21 od User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to od
WOW thx "rod k" =)

i was totaly into the single quotes, i kind of have only perl in my mind.


Thank you very much u just saved 250 lines code for me

/od

Reply With Quote
  #6  
Old July 6th, 2000, 04:06 AM
Oliver Smith Oliver Smith is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 6 Oliver Smith User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
In perl, also, single quotes indicate a non-interpolated string. So you would experience the exact same problem writing the code in Perl.

I'm not pointing this out as criticism, more because I've found a lot of Perl programmers who seem unaware of this, and always use double quotes.

Oliver

Reply With Quote
  #7  
Old July 6th, 2000, 04:36 AM
od od is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 21 od User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to od
Hi Oliver,

i have used perl in about 2 years now and i have ALWAYS used system command with single quotes "button next to the return" and it always worked, so i dunno what u are talking about.

Probably if u use some of the other "'`" it be messed up but a normal single quote "'" works just fine :=)


/od

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > arghh system()

Developer Shed Advertisers and Affiliates



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

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap