473,396 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Is it possible?: cat text.txt | python_script_which_also_gets_user_input.py

Hi there,

I run in a problem with a script, that shall work similar like the c-program
"most". It should be able to get some text on execution via a pipe but also
is interactive by the user via the curses module (for scrolling and stuff).
The problem is: if you call the script like that, you connect stdin to
text.txt and any later keyboard input is ignored, since curses also reads
from stdin.
I have the rather blurry impression that this could be possible with
threading or forking inside the script, but I nether did things like that
before and am hopeful to get some cool advice from you experienced
guys. :-)
Jul 18 '05 #1
3 2206
> I run in a problem with a script, that shall work similar like the c-program
"most". It should be able to get some text on execution via a pipe but also
is interactive by the user via the curses module (for scrolling and stuff).
The problem is: if you call the script like that, you connect stdin to
text.txt and any later keyboard input is ignored, since curses also reads
from stdin.
I have the rather blurry impression that this could be possible with
threading or forking inside the script, but I nether did things like that
before and am hopeful to get some cool advice from you experienced


I'm not sure, I've not tried this. The suggestion I'd have is redirect
the the input that curses reads to /dev/tty if you can figure out how to
do that.

Python does have some redirection capability built in the the sys
module, i.e. it's possible to separate sys.stdin and sys.__stdin__ and
handle them sepratelty. Just for tty direct IO, that would be easy. I
just don't know about curses, because it probably is outside of python.

Rob
Jul 18 '05 #2
Quoth "Robert M. Emmons" <Ro********@cs.com>:
|> I run in a problem with a script, that shall work similar like the c-program
|> "most". It should be able to get some text on execution via a pipe but also
|> is interactive by the user via the curses module (for scrolling and stuff).
|> The problem is: if you call the script like that, you connect stdin to
|> text.txt and any later keyboard input is ignored, since curses also reads
|> from stdin.
|> I have the rather blurry impression that this could be possible with
|> threading or forking inside the script, but I nether did things like that
|> before and am hopeful to get some cool advice from you experienced
|
| I'm not sure, I've not tried this. The suggestion I'd have is redirect
| the the input that curses reads to /dev/tty if you can figure out how to
| do that.
|
| Python does have some redirection capability built in the the sys
| module, i.e. it's possible to separate sys.stdin and sys.__stdin__ and
| handle them sepratelty. Just for tty direct IO, that would be easy. I
| just don't know about curses, because it probably is outside of python.

/dev/tty sounds like a good bet to me -- assuming we're on UNIX.
I wouldn't waste much time on sys.stdin - might work, but likely
sys.stdin is irrelevant to curses. File redirection that's effective
across all I/O in the process happens at the UNIX file descriptor
level, with functions like posix.dup2(). Try this -

txt = os.fdopen(os.dup(0), 'r')
os.close(0)
os.open('/dev/tty', os.O_RDONLY)

I believe some applications in this position simply use unit 2,
rather than opening /dev/tty, since it's highly likely to be open
on the terminal. While 2 is normally used for write access only,
0, 1 and 2 are all just dups of the same read/write file descriptor
open on the tty.

Donn Cave, do**@drizzle.com
Jul 18 '05 #3
Thank you for your ideas, that really helped me.
It works now. :-)

So the answer to my question is YES. :-)
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Manuel Yguel | last post by:
I try to parse an indented xml file with dom xerces c++. the file is like that : <root> <child1> <field1> foo </field1> <field2> bar </field2> </child1> <child2> <field1> foo </field1>...
1
by: Matt | last post by:
Is it possible to put XSL instructions inside JavaScript? For example, pop up a message box with the xml value: alert(value in xml); Approach #1: <script type="text/javascript">...
4
by: bart plessers | last post by:
Hello, I am making a website where the user can choose a 'skin'. This works with asp en stylesheets. In the stylesheet, a number of tags are (re)defined. The main idea is to have a limited...
4
by: Maggie | last post by:
Hi, I am in a process of creating a text version of my website and was wondering if it was possible to accomplish this without actually making the same page twice using CSS. I have a...
39
by: Mark Johnson | last post by:
It doesn't seem possible. But would the following also seem a violation of the general notions behind css? You have a DIV, say asociated with class, 'topdiv'. Inside of that you have an anchor...
14
by: J. Makela | last post by:
Hallo. This should be a pretty entertaining question for you *real* javascript writers.. I, being the lowly photoshop guy at an ad agency made the mistake of actually saying "HTML" in a...
0
by: dag | last post by:
Hi! I would like to do an overlap window, over my main window (of my application), with a Progress Bar. Exactly when I push a button of my application I want show a window, with a Progress bar,...
2
by: Bhupesh Naik | last post by:
This is a query regarding my problem to make a spell and grammar check possible in text area of a web page. We have aspx pages which are used to construct letters. The browser based screens...
2
by: Paul Hale | last post by:
Hi, I have two web forms (lets call them webform1 and webform2) that run as part of the same web application. Webform1 contains a text box. I would like to pop up a new browser window...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.