Hello,
I have read about stdin and stdout being standard input and output
streams, but I am still having trouble visualizing how they really
work and what they contain during program execution. For instance
could you use a call to fputc() and/or fseek to write a carriage
return to stdin and cause a subsequent call to getchar() to return
without the user pressing a return key? I have checked the C FAQ and
GNU C Library section on standard streams for more info and found a
lot on their usage, but not much on the internals of how they are
structured and operate. Thanks for any advice. 6 8005
"Andrew" <an***********@ ca.com> wrote: I have read about stdin and stdout being standard input and output streams, but I am still having trouble visualizing how they really work and what they contain during program execution. For instance could you use a call to fputc() and/or fseek to write a carriage return to stdin and cause a subsequent call to getchar() to return without the user pressing a return key?
No and no, in that order :) For two reasons. First, all std* streams
are unseekable. Second, stdin is input only, trying to do anything
other than read from it is a UB. (I believe that you can do ungetc
on stdin, but I have been known to be wrong :))
Similarily stdout and stderr are output only.
I have checked the C FAQ and GNU C Library section on standard streams for more info and found a lot on their usage, but not much on the internals of how they are structured and operate. Thanks for any advice.
Consider them ordinary files, except that you do not need to worry
about opening and closing them, as that is done for you automagically.
Peter
Andrew wrote: Hello,
I have read about stdin and stdout being standard input and output streams, but I am still having trouble visualizing how they really work and what they contain during program execution. For instance could you use a call to fputc() and/or fseek to write a carriage return to stdin and cause a subsequent call to getchar() to return without the user pressing a return key? I have checked the C FAQ and GNU C Library section on standard streams for more info and found a lot on their usage, but not much on the internals of how they are structured and operate. Thanks for any advice.
stdin is an input stream, hence output operations are
not meaningful[*]. Dually, stdout and stderr are output
streams, so input operations aren't usable. fseek() and
other positioning functions may or may not work, and this
may vary from one program execution to the next.
The C Standard describes what an implementation may and
must do, but not how it is to be done. P.J. Plauger's "The
Standard C Library" considers many of the issues facing a C
library implementor and exhibits a specimen implementation,
but its internals may have little resemblance to those of
the system(s) you're familiar with.
[*] ungetc() is an "output-like" operation, in a very
limited way. It will do what you're asking for,
but not what I suspect you desire.
-- Er*********@sun .com an***********@c a.com (Andrew) wrote: Hello,
I have read about stdin and stdout being standard input and output streams, but I am still having trouble visualizing how they really work and what they contain during program execution.
stdin, stdout and stderr are expressions of type 'pointer to FILE'
defined in <stdio.h>. They designate streams opened in text mode,
connected to the console by default on most (?) hosted
implementations . They "contain" user supplied input and program
generated output respectively.
For instance could you use a call to fputc() and/or fseek to write a carriage return to stdin and cause a subsequent call to getchar() to return without the user pressing a return key?
Not so. Write operations on stdin invoke undefined behaviour, as does
fflush(stdin), just in case you're tempted to use this construct.
I have checked the C FAQ and GNU C Library section on standard streams for more info and found a lot on their usage, but not much on the internals of how they are structured and operate. Thanks for any advice.
The internal structure and operation (beyond what is specified for
streams in general) is not subject of the C Standard.
HTH a bit
Regards
--
Irrwahn
(ir*******@free net.de)
"Peter Pichler" <pi*****@pobox. sk> wrote: [...] all std* streams are unseekable.
Hmm, I think it is implementation-defined behaviour.
<OT>
What about if input is redirected from a file, for example?
</OT>
Regards
--
Irrwahn
(ir*******@free net.de)
In <al************ *************** *****@4ax.com> Irrwahn Grausewitz <ir*******@free net.de> writes: "Peter Pichler" <pi*****@pobox. sk> wrote:
[...] all std* streams are unseekable.
Hmm, I think it is implementation-defined behaviour.
Not even. The implementor cannot guess how I'm going to start the
program ;-) After
prog < input > output
both stdin and stdout are seekable, if the input file exists and the
output file can be created, on both Unix and Windows.
The only thing guaranteed about the std* streams is that they are
text mode streams (unless you freopen them differently).
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de Da*****@cern.ch (Dan Pop) wrote: In <al************ *************** *****@4ax.com> Irrwahn Grausewitz <ir*******@free net.de> writes:
"Peter Pichler" <pi*****@pobox. sk> wrote:
[...] all std* streams are unseekable.
Hmm, I think it is implementation-defined behaviour.
Not even. The implementor cannot guess how I'm going to start the program ;-)
Right, I'll call that invocation-defined behaviour from now on. ;-)
--
Irrwahn
(ir*******@free net.de) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bernhard Kuemel |
last post by:
Hi!
I want to read/write commands and program input to/from /bin/bash
several times before I close the stdin pipe. However, reading
from cat hangs unless I first close the stdin pipe.
<?php
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child
|
by: lickspittle |
last post by:
Hi,
I have Python embedded with my other code, and when my other code opens
a console and redirects stdout, stdin and stderr to it, then calls
PyRun_InteractiveLoop, it immediately returns with an EOF.
After some debugging the reason for this appears to be that the stdin
and stdout that the ReadLine function in the tokeniser include are not
affected by my redirection and refer to a non-terminal so don't stall
waiting for input from my...
|
by: Harayasu |
last post by:
Hi,
Using fgets() I can read from stdin and with fputs() I can write to
stdout. Now I have two programs, one writing to stdin and the other
one reading from stdin. And I would like the second program to read
the characters the first program has written to stdin, but I don't get
it how to do this.
The program which writes to stdin:
|
by: herrcho |
last post by:
What's the difference between STDIN and Keyboard buffer ?
when i get char through scanf, i type in some characters and press
enter,
then, where do the characters go ? to STDIN or Keyboard buffer ? are
they same ?
thanks ^^
|
by: ccdrbrg |
last post by:
What is the best way to protect stdin within a library?
I am writing a terminal based program that provides plugin
capability using the dlopen() API.
Sequencing program commands (typed) and library input
prompts will not happen if stdin is supplied by pipe
or redirection.
So, I would like to include a statement in the pluggin
| |
by: velle |
last post by:
My headache is growing while playing arround with unicode in Python,
please help this novice. I have chosen to divide my problem into a few
questions.
Python 2.3.4 (#1, Feb 2 2005, 12:11:53)
on linux2
1)
Does " >>>print 'hello' " simply write to sys.stdout?
|
by: asdsd sir |
last post by:
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
|
by: BenjaMinster |
last post by:
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 sys.stdin.readline().decode("utf-8").
That is, I wrap sys.stdout in a utf-8 writer and I read utf-8 input
|
by: kimonp |
last post by:
I am running on windows XP with a fresh install of wamp5 (1.7.2) and mediawiki.
I am trying to call a perl function from within php using proc_open.
The perl script is being executed and returns a successful exit value, and I can read the results it prints to STDOUT in PHP, but the perl script does not see STDIN from PHP. Since I want to use the perl script as a filter and I don't want to create an intermediary file, this is problematic....
|
by: Gabriel Genellina |
last post by:
En Thu, 25 Sep 2008 09:49:31 -0300, Almar Klein <almar.klein@gmail.com>
escribió:
Use subprocess.PIPE
Usually the tricky part is to figure out exactly whether there is more
input or not. With Python it's easy, use the ps1 prompt.
--- begin ---
import sys
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |