Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: How to use "while" within the command in -c option of python?

Reply
Thread Tools

Re: How to use "while" within the command in -c option of python?

 
 
Ned Deily
Guest
Posts: n/a
 
      10-13-2012
In article
<(E-Mail Removed)>,
Herman <(E-Mail Removed)> wrote:
> I was just trying to do in a shell to quickly monitor a file. Imagine
> instead of printing hello, it is "os.system("cat somefile")", etc.
> Look like it works if i press an enter after the "import xxx". Thanks.


If you are using a POSIX-compatible shell, the canonical approach for
use cases like this is to use a "here document", for example:

python - <<EOF
import os
while True:
print('hello')
EOF

The "-" tells the Python interpreter to read from stdin. The shell
supplies the lines between the <<EOF and the matching EOF as stdin.

http://en.wikipedia.org/wiki/Here_document

--
Ned Deily,
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Re: How to use "while" within the command in -c option of python? Etienne Robillard Python 11 10-13-2012 10:09 PM
Re: How to use "while" within the command in -c option of python? Herman Python 0 10-13-2012 12:55 AM
Re: How to use "while" within the command in -c option of python? Dave Angel Python 0 10-13-2012 12:29 AM
How to use "while" within the command in -c option of python? Herman Python 0 10-12-2012 10:51 PM



Advertisments