Thread: arghh system()

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    21
    Rep 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

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Location
    Aalborg, Denmark
    Posts
    36
    Rep Power
    15
    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
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    21
    Rep 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
  6. #4
  7. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    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");
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    21
    Rep 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
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    6
    Rep 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
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    21
    Rep 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

Similar Threads

  1. program cinema booking system in ASP
    By jozza7 in forum Hire A Programmer
    Replies: 7
    Last Post: May 21st, 2005, 02:22 PM
  2. php/mysql programers needed
    By Tomcromp in forum Hire A Programmer
    Replies: 4
    Last Post: January 18th, 2004, 06:14 PM
  3. PHP Gameserver-booking system
    By Skaven in forum Project Help Wanted
    Replies: 0
    Last Post: January 3rd, 2004, 07:20 PM
  4. Win2k Server Stop Codes During Clean Install
    By macrohard in forum Windows Help
    Replies: 2
    Last Post: December 7th, 2003, 11:19 AM
  5. Get a FREE QUOTE of your project NOW!
    By amnistiya.com in forum Hire A Programmer
    Replies: 2
    Last Post: December 1st, 2003, 03:03 AM

IMN logo majestic logo threadwatch logo seochat tools logo