Re: merge stdin, stdout?

2010-02-05 Thread jonny lowe
On Feb 4, 8:20 pm, exar...@twistedmatrix.com wrote: On 01:56 am, jonny.lowe.12...@gmail.com wrote: Hi everyone, Is there an easy way to mergestdinandstdout? For instance suppose I havescriptthat prompts for a number and prints the number. If you execute this with redirection from a file

Re: merge stdin, stdout?

2010-02-05 Thread Gabriel Genellina
En Fri, 05 Feb 2010 17:39:07 -0300, jonny lowe jonny.lowe.12...@gmail.com escribió: On Feb 4, 8:20 pm, exar...@twistedmatrix.com wrote: On 01:56 am, jonny.lowe.12...@gmail.com wrote: What I want is to have an easy way to merge input.txt and thestdout so that output.txt look like: Enter a

merge stdin, stdout?

2010-02-04 Thread jonny lowe
Hi everyone, Is there an easy way to merge stdin and stdout? For instance suppose I have script that prompts for a number and prints the number. If you execute this with redirection from a file say input.txt with 42 in the file, then executing ./myscript input.txt output.txt the output.txt

Re: merge stdin, stdout?

2010-02-04 Thread exarkun
On 01:56 am, jonny.lowe.12...@gmail.com wrote: Hi everyone, Is there an easy way to merge stdin and stdout? For instance suppose I have script that prompts for a number and prints the number. If you execute this with redirection from a file say input.txt with 42 in the file, then executing

Re: UTF-8 and stdin/stdout?

2008-05-28 Thread Ulrich Eckhardt
Chris wrote: On May 28, 11:08 am, [EMAIL PROTECTED] wrote: Say I have a file, utf8_input, that contains a single character, é, coded as UTF-8: $ hexdump -C utf8_input  c3 a9 0002 [...] weird thing is 'c3 a9' is é on my side... and copy/pasting the é gives me 'e9' with the

Re: UTF-8 and stdin/stdout?

2008-05-28 Thread Chris
On May 28, 11:08 am, [EMAIL PROTECTED] wrote: Hi, I have problems getting my Python code to work with UTF-8 encoding when reading from stdin / writing to stdout. Say I have a file, utf8_input, that contains a single character, é, coded as UTF-8:         $ hexdump -C utf8_input        

Re: UTF-8 and stdin/stdout?

2008-05-28 Thread dave_140390
Shouldn't you do data = data.decode('utf8') ? Yes, that's it! Thanks. -- dave -- http://mail.python.org/mailman/listinfo/python-list

UTF-8 and stdin/stdout?

2008-05-28 Thread dave_140390
Hi, I have problems getting my Python code to work with UTF-8 encoding when reading from stdin / writing to stdout. Say I have a file, utf8_input, that contains a single character, é, coded as UTF-8: $ hexdump -C utf8_input c3 a9 0002 If I read this file

Re: UTF-8 and stdin/stdout?

2008-05-28 Thread Arnaud Delobelle
[EMAIL PROTECTED] writes: Hi, I have problems getting my Python code to work with UTF-8 encoding when reading from stdin / writing to stdout. Say I have a file, utf8_input, that contains a single character, é, coded as UTF-8: $ hexdump -C utf8_input c3 a9

Re: UTF-8 and stdin/stdout?

2008-05-28 Thread Martin v. Löwis
$ cat utf8_from_stdin.py import sys data = sys.stdin.read() print length of data =, len(data) sys.stdin is a byte stream in Python 2, not a character stream. To make it a character stream, do sys.stdin = codecs.getreader(utf-8)(sys.stdin) HTH, Martin --

Re: stdin, stdout, redmon

2008-01-22 Thread Bernard Desnoues
Hello, I checked under linux and it works : text.txt : first line of the text file second line of the text file test.py : import sys a = sys.stdin.readlines() x = ''.join(a) x = x.upper() sys.stdout.write(x) cat text.txt | python test.py But I reinstalled Python 2.5 under Windows XP and it

Re: stdin, stdout, redmon

2008-01-22 Thread Tim Golden
reinstalled Python 2.5 under Windows XP and it doesn't work anyway. Can you confirm that your script works with Win XP and Python 2.5 ? How are you invoking the script under WinXP? If you're using the standard file associations then stdin/stdout won't work correctly. However, they produce a specific

Re: stdin, stdout, redmon

2008-01-22 Thread John Machin
On Jan 22, 8:42 pm, Bernard Desnoues [EMAIL PROTECTED] wrote: Hello, I checked under linux and it works : text.txt : first line of the text file second line of the text file test.py : import sys a = sys.stdin.readlines() x = ''.join(a) x = x.upper() sys.stdout.write(x) cat text.txt

Re: stdin, stdout, redmon

2008-01-22 Thread Rolf van de Krol
Well, that's at least weird. I did test my code with Python 2.5 on Win XP, using the command prompt. But testing it with IDLE gives exactly the same error Bernard has. So apparently STDIN can't be accessed with IDLE. Rolf John Machin wrote: Excuse me, gentlemen, may I be your referee

Re: stdin, stdout, redmon

2008-01-22 Thread Konstantin Shaposhnikov
Hi, This is Windows bug that is described here: http://support.microsoft.com/default.aspx?kbid=321788 This article also contains solution: you need to add registry value: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies \Explorer InheritConsoleHandles = 1 (REG_DWORD type)

Re: stdin, stdout, redmon

2008-01-22 Thread Konstantin Shaposhnikov
Sorry, I meant: Alternatively you can use following command cat file | python script.py instead of cat file | script.py On Jan 22, 1:54 pm, Konstantin Shaposhnikov [EMAIL PROTECTED] wrote: Hi, This is Windows bug that is described

Re: stdin, stdout, redmon

2008-01-22 Thread Thynnus
On 1/21/2008 9:02 AM, Bernard Desnoues wrote: Hi, I've got a problem with the use of Redmon (redirection port monitor). I intend to develop a virtual printer so that I can modify data sent to the printer. FWIW: there is a nice update the RedMon (v1.7) called RedMon EE (v1.81) available

Re: stdin, stdout, redmon

2008-01-22 Thread Thynnus
On 1/22/2008 8:54 AM, Konstantin Shaposhnikov wrote: Hi, This is Windows bug that is described here: http://support.microsoft.com/default.aspx?kbid=321788 This article also contains solution: you need to add registry value:

stdin, stdout, redmon

2008-01-21 Thread Bernard Desnoues
Hi, I've got a problem with the use of Redmon (redirection port monitor). I intend to develop a virtual printer so that I can modify data sent to the printer. Redmon send the data flow to the standard input and lauchs the Python program which send modified data to the standard output (Windows

Re: stdin, stdout, redmon

2008-01-21 Thread Rolf van de Krol
According to various tutorials this should work. code |import sys data = sys.stdin.readlines() print Counted, len(data), lines.| /code Please use google before asking such questions. This was found with only one search for the terms 'python read stdin' Rolf Bernard Desnoues wrote: Hi, I've

Re: stdin, stdout, redmon

2008-01-21 Thread Bernard Desnoues
Rolf van de Krol a écrit : According to various tutorials this should work. code |import sys data = sys.stdin.readlines() print Counted, len(data), lines.| /code Please use google before asking such questions. This was found with only one search for the terms 'python read stdin'

Re: stdin, stdout, redmon

2008-01-21 Thread Rolf van de Krol
I don't know what you did with your Python installation, but for me this works perfectly. test3.py contains: code import sys print sys.stdin.readlines() /code test.txt contains: code Testline1 Testline2 /code Output of 'python test3.py test.txt' is: code ['Testline1\n', 'Testline2'] /code

[issue1786] pdb should set stdin+stdout around exec call

2008-01-15 Thread Guido van Rossum
Guido van Rossum added the comment: Committed revision 59984 (2.6). Decided not to backport this to 2.5. -- resolution: - fixed status: open - closed versions: -Python 2.5 __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1786

[issue1786] pdb should set stdin+stdout around exec call

2008-01-14 Thread Guido van Rossum
Guido van Rossum added the comment: Here's an improved patch -- the recursive debugger invocation should pass the I/O settings on. -- assignee: - gvanrossum keywords: +easy Added file: http://bugs.python.org/file9171/pdb.diff __ Tracker [EMAIL

[issue1786] pdb should set stdin+stdout around exec call

2008-01-10 Thread Guido van Rossum
priority: low severity: normal status: open title: pdb should set stdin+stdout around exec call type: behavior versions: Python 2.5, Python 2.6, Python 3.0 Added file: http://bugs.python.org/file9120/pdb.diff __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1786

[issue1786] pdb should set stdin+stdout around exec call

2008-01-10 Thread Guido van Rossum
Changes by Guido van Rossum: -- keywords: +patch __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1786 __ ___ Python-bugs-list mailing list Unsubscribe:

Re: annoying stdin/stdout + pipes problem

2007-09-24 Thread per9000
replace3.py echo --- cat input.txt | python replace3.py from sys import stdin, stdout def censor(foo, bar, input): return input.replace(foo, bar) fp = open('/dev/tty', 'r+') fp.write('Remove what? ') i = fp.readline().strip() fp.write('Replace %s with what? ' %i) o = fp.readline().strip

Re: annoying stdin/stdout + pipes problem

2007-09-24 Thread Gabriel Genellina
En Mon, 24 Sep 2007 04:04:07 -0300, per9000 [EMAIL PROTECTED] escribi�: On 23 Sep, 18:24, Damjan [EMAIL PROTECTED] wrote: I want to create a program that reads input from stdio that can prompt a user for input while doing so without getting into problems. ... The trick (which works on

annoying stdin/stdout + pipes problem

2007-09-23 Thread per9000
certain words ***cat replace2.py from sys import stdin, stdout def censor(foo, bar, input): return input.replace(foo, bar) # i = raw_input('Remove what? ').strip() # o = raw_input('Replace %s with what? ' %i).strip() for line in stdin.xreadlines(): line = censor('foo', 'candy', line

Re: annoying stdin/stdout + pipes problem

2007-09-23 Thread Damjan
I want to create a program that reads input from stdio that can prompt a user for input while doing so without getting into problems. ... As you can see I have commented out what I'd like to do but do not know how to. Can I somehow halt the previous print to stdout (cat input.txt) - if so can

Re: Smarter way to do this? Unicode + stdin, stdout

2006-12-17 Thread Martin v. Löwis
BenjaMinster schrieb: I want to read and write unicode on stdin and stdout. I can't seem to find any way to force sys.stdin.encoding and sys.stdout.encoding to be utf-8, so I've got the following workaround: What operating system are you using? Why do you want to do this? Python attempts to

Smarter way to do this? Unicode + stdin, stdout

2006-12-16 Thread BenjaMinster
I want to read and write unicode on stdin and stdout. I can't seem to find any way to force sys.stdin.encoding and sys.stdout.encoding to be utf-8, so I've got the following workaround: import codecs, sys out = codecs.getwriter(utf-8)(sys.stdout) def tricky(): return

RE: Some general questions about using stdin,stdout....

2006-02-17 Thread asdsd sir
thank you very much for your help... my big mistake,was to believe that | is the pipe symbol for both,unix and python... it is really annoying,how such a simple thing can mess things Thank you for clearing this out. _ Free blogging

Re: Some general questions about using stdin,stdout....

2006-02-17 Thread Steve Holden
asdsd sir wrote: thank you very much for your help... my big mistake,was to believe that | is the pipe symbol for both,unix and python... it is really annoying,how such a simple thing can mess things Thank you for clearing this out. It is indeed annoying when assumptions we carry from

Some general questions about using stdin,stdout....

2006-02-16 Thread asdsd sir
Hi!I'm new in Python and i'd like to ask some general questions about stdin,stdout... Firstly... if we type like something like : cat file.txt|python somefile.py #somefile.py import sys text=sys.stdin.read() ...then sys.stdin.read() will read from cats stdout... However,if i type

Re: Some general questions about using stdin,stdout....

2006-02-16 Thread Dan
Hello. If you're new to Python, then input/output isn't the best place to start. Begin with the tutorial: http://docs.python.org/tut/tut.html Other documentation is also linked to from there. However, I will briefly answer your questions. print hello|sys.stdin.read() In Python the |

Re: Some general questions about using stdin,stdout....

2006-02-16 Thread Diez B. Roggisch
asdsd sir wrote: Hi!I'm new in Python and i'd like to ask some general questions about stdin,stdout... Firstly... if we type like something like : cat file.txt|python somefile.py #somefile.py import sys text=sys.stdin.read() ...then sys.stdin.read() will read from

Redirecting stdin/stdout to self

2006-01-23 Thread Jan Danielsson
Hello, I thought I'd write a program to collect information from pf (packet filter) and insert it into a postgresql database for review on a web page. First I checked if this has been done already, and found that it has.. Using Perl and SQLite in a program called hatchet. Well, I want to do it

Re: Redirecting stdin/stdout to self

2006-01-23 Thread Grant Edwards
On 2006-01-23, Jan Danielsson [EMAIL PROTECTED] wrote: And if I'm reading it correctly, the Perl script's process starts tcpdump, but redirects its output to its own input, and reads it line by line. [...] ...however, the Perl script solution looks interresting.. Is it possible to do

Re: Redirecting stdin/stdout to self

2006-01-23 Thread Grant Edwards
On 2006-01-23, Grant Edwards [EMAIL PROTECTED] wrote: On 2006-01-23, Jan Danielsson [EMAIL PROTECTED] wrote: And if I'm reading it correctly, the Perl script's process starts tcpdump, but redirects its output to its own input, and reads it line by line. [...] ...however, the Perl script

Re: Redirecting stdin/stdout to self

2006-01-23 Thread Dan M
And if I'm reading it correctly, the Perl script's process starts tcpdump, but redirects its output to its own input, and reads it line by line. And to clarify, what the Perl script is doing is redirecting the standard error to standard out. STDIN is file handle 0, STDOUT is file handle 1, and

Re: closing stdin, stdout and stderr

2005-12-27 Thread Donn Cave
In article [EMAIL PROTECTED], Martijn Brouwer [EMAIL PROTECTED] wrote: ... I read this one, which was the reason that I tried os.close instead of sys.stdXXX.close(). But I would like to know why it does not close a file discriptor is I call its close method(). They're special. I suppose

closing stdin, stdout and stderr

2005-12-26 Thread Martijn Brouwer
I am writing a unix daemon in python, so I want to close stdin, stdout and stderr. My first attempt was to the standard file descriptors using their close() methods. After closing stdout, I could not print anymore, so this seemed to work. However, later I noticed that they were not really closed

Re: closing stdin, stdout and stderr

2005-12-26 Thread Robin Becker
Martijn Brouwer wrote: I am writing a unix daemon in python, so I want to close stdin, stdout and stderr. My first attempt was to the standard file descriptors using their close() methods. After closing stdout, I could not print anymore, so this seemed to work. However, later I noticed

Re: closing stdin, stdout and stderr

2005-12-26 Thread Robin Becker
Robin Becker wrote: Martijn Brouwer wrote: I am writing a unix daemon in python, so I want to close stdin, stdout and stderr. My first attempt was to the standard file descriptors using their close() methods. After closing stdout, I could not print anymore, so this seemed to work. However

Re: closing stdin, stdout and stderr

2005-12-26 Thread Martijn Brouwer
On Mon, 2005-12-26 at 23:13 +, Robin Becker wrote: Martijn Brouwer wrote: I am writing a unix daemon in python, so I want to close stdin, stdout and stderr. My first attempt was to the standard file descriptors using their close() methods. After closing stdout, I could not print

Re: closing stdin, stdout and stderr

2005-12-26 Thread Martijn Brouwer
On Mon, 2005-12-26 at 23:15 +, Robin Becker wrote: Robin Becker wrote: Martijn Brouwer wrote: I am writing a unix daemon in python, so I want to close stdin, stdout and stderr. My first attempt was to the standard file descriptors using their close() methods. After closing stdout

Re: stdin - stdout

2005-08-20 Thread Jorgen Grahn
On Fri, 19 Aug 2005 15:26:27 GMT, max(01)* [EMAIL PROTECTED] wrote: hi. i was wondering, what's the simplest way to echo the standard input to the standard output, with no modification. i came up with: ... but i guess there must be a simpler way. using bash i simply do 'cat', *sigh*! ...

Re: stdin - stdout

2005-08-20 Thread Jeff Schwab
max(01)* wrote: i was wondering, what's the simplest way to echo the standard input to the standard output, with no modification. ... ps: in perl you ca do this: ... while ($line = STDIN) { print STDOUT ($line); } ... I guess you could, but there wouldn't be much point. In

stdin - stdout

2005-08-19 Thread max(01)*
hi. i was wondering, what's the simplest way to echo the standard input to the standard output, with no modification. i came up with: ... while True: try: raw_input() except EOFError: break ... but i guess there must be a simpler way. using bash i simply do 'cat', *sigh*!

Re: stdin - stdout

2005-08-19 Thread limodou
2005/8/19, max(01)* [EMAIL PROTECTED]: hi. i was wondering, what's the simplest way to echo the standard input to the standard output, with no modification. i came up with: ... while True: try: raw_input() except EOFError: break ... but i guess there must be a

Re: stdin - stdout

2005-08-19 Thread Dan Sommers
On Fri, 19 Aug 2005 15:26:27 GMT, max(01)* [EMAIL PROTECTED] wrote: ps: in perl you ca do this: ... while ($line = STDIN) { print STDOUT ($line); } ... import fileinput import sys for line in fileinput.input(): sys.stdout.write(line) Regards, Dan -- Dan Sommers

Re: stdin - stdout

2005-08-19 Thread gry
import sys for l in sys.stdin: sys.stdout.write(l) -- George -- http://mail.python.org/mailman/listinfo/python-list

Re: stdin - stdout

2005-08-19 Thread Steven Bethard
max(01)* wrote: i was wondering, what's the simplest way to echo the standard input to the standard output, with no modification. import sys for line in iter(sys.stdin.readline, ''): sys.stdout.write(line) Note that this uses the second form of iter(), which calls its first argument

Re: stdin - stdout

2005-08-19 Thread Steven Bethard
gry@ll.mit.edu wrote: import sys for l in sys.stdin: sys.stdout.write(l) This is fine if you don't need the reads and writes of lines to run in lockstep. File iterators read into a buffer, so you'll probably read 4096 bytes from stdin before you ever write a line to stdout. If

Re: stdin - stdout

2005-08-19 Thread John Machin
limodou wrote: 2005/8/19, max(01)* [EMAIL PROTECTED]: hi. i was wondering, what's the simplest way to echo the standard input to the standard output, with no modification. i came up with: ... while True: try: raw_input() except EOFError: break ... but i guess there must be a

Re: stdin/stdout fileno() always returning -1 from windows service

2005-07-18 Thread Jeff Epler
On Sun, Jul 17, 2005 at 06:43:00PM -0700, chuck wrote: I have found that sys.stdin.fileno() and sys.stdout.fileno() always return -1 when executed from within a win32 service written using the win32 extensions for Python. Anyone have experience with this or know why? because there *is* no

Re: stdin/stdout fileno() always returning -1 from windows service

2005-07-18 Thread chuck
Interesting. The stdin and stdout objects in my service seems respond to returing a string for the statements str(sys.stdin) and str(sys.stdout). I guess they are just not attached to files? Can you provide a reference (MSDN or otherwise) that indicates that Windows Services don't have standard

Re: stdin/stdout fileno() always returning -1 from windows service

2005-07-18 Thread Jeff Epler
It seems to simply be common wisdom. e.g., http://mail.python.org/pipermail/python-win32/2004-September/002332.html http://mail.mems-exchange.org/pipermail/quixote-users/2004-March/002743.html http://twistedmatrix.com/pipermail/twisted-python/2001-December/000644.html etc If you can find chapter

Re: stdin/stdout fileno() always returning -1 from windows service

2005-07-18 Thread chuck
common wisdom interesting. The value of the closed attribute is False when tested from within the service. Still digging -- http://mail.python.org/mailman/listinfo/python-list

stdin/stdout fileno() always returning -1 from windows service

2005-07-17 Thread chuck
I have found that sys.stdin.fileno() and sys.stdout.fileno() always return -1 when executed from within a win32 service written using the win32 extensions for Python. Anyone have experience with this or know why? -- http://mail.python.org/mailman/listinfo/python-list

Re: Redirecting stdin, stdout, and stderr to a window

2004-12-16 Thread Michael Fuhr
Michael McGarry [EMAIL PROTECTED] writes: How do I redirect stdin, stdout and stderr to a window? I am using Qt for GUI. I don't know what specific mechanisms Qt provides, but the general solution is to write a class that implements I/O methods like read, readline, and write, and assign

Re: SOAPpy/ZSI/Twisted SOAP over stdin/stdout?

2004-12-01 Thread Harry George
Harry George [EMAIL PROTECTED] writes: Normally the SOAP Servers are designed to take control of a port and run their own sockets via inheritance from SocktServer. But under inetd and xinetd, the port is controlled elsewhere and the service just gets the stdin/stdout. I need to configure

<    1   2