Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > PHP

Reply
 
LinkBack Thread Tools Display Modes
Old 01-14-2003, 06:44 AM   #1 (permalink)
anon
Guest
 
Posts: n/a
using exec() and getting output

I want to be able to execute UNIX commands from a website in PHP and get the output back., I have tried using exec() (I hope that actually exists ) but I get nothing back. Is this possible to do? And if so what am I doing wrong?
  Reply With Quote
Old 01-15-2003, 03:53 PM   #2 (permalink)
Ilya020
Techno Rat
 
Ilya020's Avatar
 
Join Date: Jan 2003
Location: San Diego
Posts: 559
Ilya020 is on a distinguished road
Send a message via AIM to Ilya020
well, have you tried asking maxim?


That might help...



Ilya
__________________
> SELECT * FROM users WHERE clue > 0
0 rows returned
Ilya020 is offline   Reply With Quote
Old 01-15-2003, 05:23 PM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
weird, i thought i replied to this thread last night, but maybe i was just thinking about it.

it would help to figure out what type of script you want to execute. most likely the answer is a big no.. that you can't send variables back to your php script after executing some other script.

i'm sure there are ways to do it though , .. for example.. make the script that you are executing create a text file with the output it generates... then you can use php to grab each line of that text file into an array.

PHP Code:
exec(somescript.sh);
$array=file("/path/to/txt/file.txt");

foreach(
$array as $each){
  echo 
$each "<br>\n";
}
?> 
you might have to execute the script and read the text file in 2 different php pages because i don't know if your script would be done executing before php tried to read the txt file. this is why i wish php had some sort of timer function built in.

also, .. instead of just having your script create a file, make sure it erases the file first some how .. or you might get bad data.

have fun =)
sde is offline   Reply With Quote
Old 01-15-2003, 05:45 PM   #4 (permalink)
anon
Guest
 
Posts: n/a
Thanks, to bad, would be a good alternative when on my parents computer and to lazy to open up PuTTy
  Reply With Quote
Old 01-15-2003, 07:49 PM   #5 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
too lazy to open putty!!! you make me laugh.

/me clicks putty icon in quick-launch once, .. then double clicks my server profile.

/me thinks .. "wow, that was quicker than opening internet explorer and typing in a url"
sde is offline   Reply With Quote
Old 01-15-2003, 08:23 PM   #6 (permalink)
anon
Guest
 
Posts: n/a
/me to lazy to click SSH button and enter password

/me also to lazy sometimes to walk 50 feet, do iptables -F, then walk back and SSH in
  Reply With Quote
Old 01-16-2003, 02:53 PM   #7 (permalink)
Ilya020
Techno Rat
 
Ilya020's Avatar
 
Join Date: Jan 2003
Location: San Diego
Posts: 559
Ilya020 is on a distinguished road
Send a message via AIM to Ilya020
/me thinks ...losers...




Ilya
__________________
> SELECT * FROM users WHERE clue > 0
0 rows returned
Ilya020 is offline   Reply With Quote
Old 01-19-2003, 06:13 PM   #8 (permalink)
anon
Guest
 
Posts: n/a
sde, ok, I made a file in /home/vlad called asd and did chmod 777 on it, then I made a script to rm -rf it and when i did exec it didn't work O_O This is going to be along night...

/me looks at php.net and docs for exec, after 10 seconds slaps head and notices these lines:

shell_exec -- Execute command via shell and return complete output as string
system -- Execute an external program and display output

DOH!

/me slaps head.

system("ls");
works
system("ls --color -F");
works (although it is unreadable because it returns characters that only the shell understands, or unless you are addicted to bash)
but
system("rm -rf /home/vlad/lll");
does not workand I don't know why .
the user is nobody and I have no idea why they can't rm it. I made the file owned by them and they still can't rm it. I don't know why....


EDIT: I have put a file called /www/htdocs/lll and have chmod 777 it and chown nobody it but still they can't rm -rf it...
  Reply With Quote
Old 01-19-2003, 06:34 PM   #9 (permalink)
Ilya020
Techno Rat
 
Ilya020's Avatar
 
Join Date: Jan 2003
Location: San Diego
Posts: 559
Ilya020 is on a distinguished road
Send a message via AIM to Ilya020
1. try chown nobody:nobody 777 asd
2. you can just do rm for files....duh!

Ilya
__________________
> SELECT * FROM users WHERE clue > 0
0 rows returned
Ilya020 is offline   Reply With Quote
Old 01-19-2003, 06:40 PM   #10 (permalink)
anon
Guest
 
Posts: n/a
1.)No chown nobody:nobody asd;chmod 777 asd; and the group doesn't matter.... It wouldn't make a difference.
2.)rm -rf makes me feel powerful
  Reply With Quote
Old 01-19-2003, 07:49 PM   #11 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
so are you saying it worked? and you got output?
sde is offline   Reply With Quote
Old 01-19-2003, 07:53 PM   #12 (permalink)
Ilya020
Techno Rat
 
Ilya020's Avatar
 
Join Date: Jan 2003
Location: San Diego
Posts: 559
Ilya020 is on a distinguished road
Send a message via AIM to Ilya020
what output would you get from rm -fr foo?

"file removed"?:p


Ilya
__________________
> SELECT * FROM users WHERE clue > 0
0 rows returned
Ilya020 is offline   Reply With Quote
Old 01-20-2003, 06:59 AM   #13 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
"file foo does not exist"
sde is offline   Reply With Quote
Old 01-20-2003, 07:33 AM   #14 (permalink)
anon
Guest
 
Posts: n/a
Quote:
Originally posted by sde
"file foo does not exist"
no, no output at all, AND the file exists... .
  Reply With Quote
Old 01-20-2003, 08:22 AM   #15 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
oh geesh .. why do i even post. illya was asking what type of output that command could produce.

of course there is no output if the file exists. if it did not exist, you would probably get output of some kind at least in the terminal. that is what i was referring too.
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 07:06 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting