Re: how to invoke the shell command and then get the result in python

2006-12-06 Thread Nick Craig-Wood
Fredrik Lundh <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > > Assuming the script isn't setuid, this would do no more damage than the > > user could do directly on the command line. > > except that when the user is typing things into the command line, he > *knows* that he's typing

Re: how to invoke the shell command and then get the result in python

2006-12-05 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > Assuming the script isn't setuid, this would do no more damage than the > user could do directly on the command line. except that when the user is typing things into the command line, he *knows* that he's typing things into the command line. -- http://mail.python.o

Re: how to invoke the shell command and then get the result in python

2006-12-05 Thread [EMAIL PROTECTED]
Nick Craig-Wood wrote: > > What if I entered "; rm -rf * ;" as my pattern? > Assuming the script isn't setuid, this would do no more damage than the user could do directly on the command line. I agree, when dealing with web applications or setuid programs, direct shell access isn't a good idea.

Re: how to invoke the shell command and then get the result in python

2006-12-05 Thread Nick Craig-Wood
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Also, for a wrapper around popen, try commands: > >import commands > >pattern = raw_input('pattern to search? ') >print commands.getoutput('grep %s *.txt' % pattern) What if I entered "; rm -rf * ;" as my pattern? Don't ever pass user

Re: how to invoke the shell command and then get the result in python

2006-12-05 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > Also, for a wrapper around popen, try commands: > > import commands > > pattern = raw_input('pattern to search? ') > print commands.getoutput('grep %s *.txt' % pattern) that's not quite as portable as the other alternatives, though. "grep" is at least availabl

Re: how to invoke the shell command and then get the result in python

2006-12-05 Thread [EMAIL PROTECTED]
Fredrik Lundh wrote: > import os > for line in os.popen("grep pattern *.txt"): > print line, > > also see os.system and subprocess. > > note that if you want to write portable code, you can implement your own > "grep" using the "re" module: > Also, for a wrapper a

Re: how to invoke the shell command and then get the result in python

2006-12-04 Thread Fredrik Lundh
Bin Chen wrote: > I want to do following: get a user input regex, then pass this as a > parameter to grep, and then get the result from grep. > > Any code snip to implement the similar function? I am a python newbie. import os for line in os.popen("grep pattern *.txt"):

how to invoke the shell command and then get the result in python

2006-12-04 Thread Bin Chen
Hi, I want to do following: get a user input regex, then pass this as a parameter to grep, and then get the result from grep. Any code snip to implement the similar function? I am a python newbie. Thanks a lot. Bin -- http://mail.python.org/mailman/listinfo/python-list