Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
09-15-2005, 02:55 PM
|
#1
|
Member
Registered: Sep 2003
Posts: 52
Rep:
|
How to send CTRL-D to child process via a pipe?
I am successful at spawning a child process and connect its stdin/stdout to two pipes. The program (gdb) needs input. I tried fputc('q', f); fputc('\r', f); and fputs("q", f), but none worked.
|
|
|
09-15-2005, 03:03 PM
|
#2
|
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507
Rep: 
|
Did you try fputs("q\n",f);? If you really want to send CTRL-D, send 0x04.
|
|
|
09-15-2005, 03:06 PM
|
#3
|
Member
Registered: Sep 2003
Posts: 52
Original Poster
Rep:
|
Tried fputs("q\n",f) - did not work. :-(
|
|
|
09-15-2005, 03:27 PM
|
#4
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,793
|
Can you issue other commands to gdb successfully and get their output ?
|
|
|
09-15-2005, 03:39 PM
|
#5
|
Member
Registered: Sep 2003
Posts: 52
Original Poster
Rep:
|
I found that if I do fflush(f); after fputs, then it works.
And also setting setvbuf(f, NULL, _IOLBF, 0); also works (fflush not needed).
It's strange I have to send fputs("h\n", f) - I thought it should be the CR key - \r.
|
|
|
09-15-2005, 05:29 PM
|
#6
|
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507
Rep: 
|
\r by itself is a mac thing. \n is the unix way.  (Newline).
|
|
|
09-15-2005, 05:56 PM
|
#7
|
Member
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895
Rep:
|
Quote:
Originally posted by Matir
\r by itself is a mac thing. \n is the unix way. (Newline).
|
And Windows is a combination of CRLF. (e.g. \r\n.) 
|
|
|
09-15-2005, 06:14 PM
|
#8
|
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507
Rep: 
|
Quote:
Originally posted by deiussum
And Windows is a combination of CRLF. (e.g. \r\n.)
|
Yep, sure is. Why they thought they needed TWO characters for the same thing that is accomplished by one in every other operating system is beyond me. 
|
|
|
09-15-2005, 07:34 PM
|
#9
|
Member
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895
Rep:
|
Technically, they aren't the same, though. CR returns the cursor to the beginning of the line, and LF moves the cursor down a line, (but doesn't necessarily return it to the beginning of the line.) In Windows, though, when writing a \n it is typically translated underneath to \r\n when writing to text-mode files.
|
|
|
09-15-2005, 08:00 PM
|
#10
|
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507
Rep: 
|
Yes, that is true. But I have honestly never seen any good use of one by itself in windows. Have you? 
|
|
|
09-15-2005, 08:09 PM
|
#11
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,793
|
Quote:
Why they thought they needed TWO characters for the same thing that is accomplished by one in every other operating system is beyond me.
|
This is wrong, many of the non Unix/Unix like O/Ses use CR-LF, and not exactly the problem.
Every terminal or terminal emulator need both CR and LF to go to the next line, including GNU/Linux and Unix.
Before Unix and C were invented, that convention was used too for representing an end of line in text files on all operating systems using ASCII. That was easing the display of a file on a screen (or a teletype) as no processing was required to "cat" a file.
C created the "\n" convention (newline) to represent the end of lines in text files, regardless of the underlying O/S (of course at the beginning the only C underlying O/S was Unix).
That was saving a little storage space, and easing all programs dealing with files (a single character is faster to locate that two) and improve response time of interactive programs at a time when sending one byte could cost a noticeable amount of time ...
However that added some complexity to the terminal drivers, which had (and still have) to convert this delimitor in what the terminal expects/sends.
See the numerous stty options to deal with that mess: inlcr igncr icrnl onlcr ocrnl onocr onlret echonl
|
|
|
All times are GMT -5. The time now is 11:48 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|