The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
arghh system()
Discuss arghh system() in the PHP Development forum on Dev Shed. arghh system() PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

July 4th, 2000, 06:33 AM
|
|
Junior Member
|
|
Join Date: Jul 2000
Posts: 21
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
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
|

July 4th, 2000, 09:10 AM
|
|
Contributing User
|
|
Join Date: Feb 2000
Location: Aalborg, Denmark
Posts: 36
Time spent in forums: < 1 sec
Reputation Power: 14
|
|
|
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
|

July 5th, 2000, 11:21 AM
|
|
Junior Member
|
|
Join Date: Jul 2000
Posts: 21
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
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
|

July 5th, 2000, 12:28 PM
|
|
Apprentice Deity
|
|
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237

Time spent in forums: 4 m 8 sec
Reputation Power: 17
|
|
|
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");
|

July 6th, 2000, 01:25 AM
|
|
Junior Member
|
|
Join Date: Jul 2000
Posts: 21
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
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
|

July 6th, 2000, 04:06 AM
|
|
Junior Member
|
|
Join Date: Jul 2000
Posts: 6
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
|

July 6th, 2000, 04:36 AM
|
|
Junior Member
|
|
Join Date: Jul 2000
Posts: 21
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
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
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|