- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Reading Keyboard inputs
Operating System - Linux
1753937
Members
9485
Online
108811
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-25-2003 04:25 PM
тАО12-25-2003 04:25 PM
Reading Keyboard inputs
Can i give input to Gnome-terminal using programs(in C or Java)?.
If i give the input to one Gnome-terminal like ls,hostname and etc.How can i get the commands from the terminal in my program?.
If i give the input to one Gnome-terminal like ls,hostname and etc.How can i get the commands from the terminal in my program?.
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-25-2003 07:31 PM
тАО12-25-2003 07:31 PM
Re: Reading Keyboard inputs
A terminal is a terminal.
stdin is the keyboard. That should do it.
The read command stops the program nicely and waits for input followed by a return.
That should be enough unless you want to script it.
while read -r aa
do
echo $aa
done < input_file
SEP
stdin is the keyboard. That should do it.
The read command stops the program nicely and waits for input followed by a return.
That should be enough unless you want to script it.
while read -r aa
do
echo $aa
done < input_file
SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-28-2003 07:42 PM
тАО12-28-2003 07:42 PM
Re: Reading Keyboard inputs
However, if you want to use C it all gets a little more complicated. You can use the standard C routines such as getc and scanf and all that but they are all a little disappointing because linux, like unix, will not give you anything until the "enter" key is pressed.
All is not lost, however, because you can change this behavior by changing the terminal into what is know as "raw" mode. In other words, characters are "unbuffered" which basically means your "getc()" works as you would expect. Sadly, this can drastically slow the application down if you don't handle it correctly. Single character at a time reads, are horribley expensive when you do lots and lots of them so use functions that read specified number of characters when you can.
For all of this, there is no useful "man" page that I have ever found but a quick google search turned up the following link which might be usefull.
http://linux.cis.nctu.edu.tw/docs/woven/HOWTO/Serial-Programming-HOWTO-2.html
If all this sounds all a bit horrid have a look at the "curses" package which does most of the nasty stuff for you and makes doing cursor positioning stuff a lot easier too.
Sorry, can't help you on the Java front though.
All is not lost, however, because you can change this behavior by changing the terminal into what is know as "raw" mode. In other words, characters are "unbuffered" which basically means your "getc()" works as you would expect. Sadly, this can drastically slow the application down if you don't handle it correctly. Single character at a time reads, are horribley expensive when you do lots and lots of them so use functions that read specified number of characters when you can.
For all of this, there is no useful "man" page that I have ever found but a quick google search turned up the following link which might be usefull.
http://linux.cis.nctu.edu.tw/docs/woven/HOWTO/Serial-Programming-HOWTO-2.html
If all this sounds all a bit horrid have a look at the "curses" package which does most of the nasty stuff for you and makes doing cursor positioning stuff a lot easier too.
Sorry, can't help you on the Java front though.
Never preceed any demonstration with anything more predictive than "watch this"
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP