Assume stdout is closed and if i now
want to open stdout, how to open it?
IS this correct way of opening stdout
fopen(stdout,"/dev/null");
Thanks
Prasanna Bhat Mavinkuli 16 39389
<bo*******@yahoo.co.in> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com... Assume stdout is closed and if i now want to open stdout, how to open it?
Don't close it. ("Doctor, when I do it it hurts.", "Don't do it.")
IS this correct way of opening stdout
fopen(stdout,"/dev/null");
Oh my goodness...
Alex
please somebody explain me how to open STDOUT?
<bo*******@yahoo.co.in> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com... please somebody explain me how to open STDOUT?
It's already open upon entry to main(). Just don't close it and you'll be
OK.
Alex bo*******@yahoo.co.in wrote: Assume stdout is closed and if i now want to open stdout, how to open it?
Don't close it. If it is closed :
int fd;
fd = open("/dev/tty", O_WRONLY);
stdout = fdopen(fd, "w");
This code depends on UNIX, since closing / opening any of the standard
streams is probably undefined :)
IS this correct way of opening stdout
fopen(stdout,"/dev/null");
Depends. If you actually want to use data send to stdout : no. If you
don't care : yes
Igmar
On Thu, 08 Sep 2005 00:01:41 -0700, boss_bhat wrote: Assume stdout is closed and if i now want to open stdout, how to open it?
If it is closed you can't portably reopen it in C.
IS this correct way of opening stdout
fopen(stdout,"/dev/null");
No, fopen() takes a pointer to a string specifying a file name as its
first argument, and one specifying a mode as its second.
What you can do is change the file stdout is open to using the freopen()
function:
freopen("/dev/null", "w", stdout)
The 3rd argument must be an existing open stream for this to be valid, so
just make sure you don't close stdout if you want to do this.
Lawrence bo*******@yahoo.co.in wrote:
# Assume stdout is closed and if i now
# want to open stdout, how to open it?
#
# IS this correct way of opening stdout
#
# fopen(stdout,"/dev/null");
Don't. Use
freopen("/dev/null","w",stdout)
instead.
--
SM Ryan http://www.rawbw.com/~wyrmwif/
She broke your heart and inadvertently drove men to deviant lifestyles.
SM Ryan <wy*****@tango-sierra-oscar-foxtrot-tango.fake.org> wrote: bo*******@yahoo.co.in wrote: # Assume stdout is closed and if i now # want to open stdout, how to open it? # # IS this correct way of opening stdout # # fopen(stdout,"/dev/null");
Don't. Use freopen("/dev/null","w",stdout) instead.
1. I know of several systems that don't know anything about /dev/null.
2. On the ones that do, writing to /dev/null is usually not the same
as writing to whatever-stdout-happened-to-point-to on program
startup.
3. Calling freopen with a third parameter that does not currently
point to a stream invokes undefined behaviour (AFAIK).
To OP:
Simply don't close stdout, if you want to make further use of it.
Best regards
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc : http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc frequent answers: http://benpfaff.org/writings/clc.
"Alexei A. Frounze" wrote: <bo*******@yahoo.co.in> wrote in message news:11**********************@g47g2000cwa.googlegr oups.com... please somebody explain me how to open STDOUT?
It's already open upon entry to main(). Just don't close it and you'll be OK.
And if you need to associate stdout with something else for whatever
reason, check out freopen().
--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Igmar Palsenberg wrote: bo*******@yahoo.co.in wrote: Assume stdout is closed and if i now want to open stdout, how to open it?
Don't close it. If it is closed :
int fd;
fd = open("/dev/tty", O_WRONLY); stdout = fdopen(fd, "w");
stdout isn't an l-value.
[...]
--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Kenneth Brody wrote: Don't close it. If it is closed :
int fd;
fd = open("/dev/tty", O_WRONLY); stdout = fdopen(fd, "w");
stdout isn't an l-value.
Depends. On this system, it is. On systems where stdout is a macro,
you're in trouble. If that's the case : stick with freopen()
Igmar
Irrwahn Grausewitz <ir*******@freenet.de> wrote:
# SM Ryan <wy*****@tango-sierra-oscar-foxtrot-tango.fake.org> wrote:
# >bo*******@yahoo.co.in wrote:
# ># Assume stdout is closed and if i now
# ># want to open stdout, how to open it?
# >#
# ># IS this correct way of opening stdout
# >#
# ># fopen(stdout,"/dev/null");
-----------
# >
# >Don't. Use
# > freopen("/dev/null","w",stdout)
-----------
# >instead.
#
# 1. I know of several systems that don't know anything about /dev/null.
---------
Apparently it meant something to the original poster.
If he had used "[15,4]:kumquat.rfd", I would've copied
"[15,4]:kumquat.rfd" whether I use RMS or not.
# 2. On the ones that do, writing to /dev/null is usually not the same
# as writing to whatever-stdout-happened-to-point-to on program
# startup.
The original poster didn't want to write to whatever-stdout-happened-to-point-to.
# 3. Calling freopen with a third parameter that does not currently
# point to a stream invokes undefined behaviour (AFAIK).
Hence the whole "Don't [fclose stdout and fopen again]."
"I hate when you mortals need all the details spelled out."
--
SM Ryan http://www.rawbw.com/~wyrmwif/
If your job was as meaningless as theirs, wouldn't you go crazy too?
SM Ryan <wy*****@tango-sierra-oscar-foxtrot-tango.fake.org> wrote: Irrwahn Grausewitz <ir*******@freenet.de> wrote:
<snip># 1. I know of several systems that don't know anything about /dev/null.
Apparently it meant something to the original poster. If he had used "[15,4]:kumquat.rfd", I would've copied "[15,4]:kumquat.rfd" whether I use RMS or not.
Which would not have been the "correct way of opening stdout", too.
Well, at least in the realm of comp.lang.c.
# 2. On the ones that do, writing to /dev/null is usually not the same # as writing to whatever-stdout-happened-to-point-to on program # startup.
The original poster didn't want to write to whatever-stdout-happened-to-point-to.
Umm. I cannot tell, he neither claimed he wanted, nor the opposite.
<snip>
"I hate when you mortals need all the details spelled out."
"I hate it when people use the least appropriate quoting character
in a C language group."
Best regards
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc : http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc frequent answers: http://benpfaff.org/writings/clc.
In article <43***********************@news.xs4all.nl>,
Igmar Palsenberg <ig***@jdimedia.local> wrote: Kenneth Brody wrote:
stdout isn't an l-value.
Depends. On this system, it is. On systems where stdout is a macro, you're in trouble.
C89 -defines- stdout as being a macro.
It might happen that the expansion of the macro gives you something
that could be used as an l-value, but you shouldn't count on that.
A common Unix value for stdout is the local equivilent of &__iob[1]
--
"Who Leads?" / "The men who must... driven men, compelled men."
"Freak men."
"You're all freaks, sir. But you always have been freaks.
Life is a freak. That's its hope and glory." -- Alfred Bester, TSMD
Igmar Palsenberg wrote: Kenneth Brody wrote:
Don't close it. If it is closed :
int fd;
fd = open("/dev/tty", O_WRONLY); stdout = fdopen(fd, "w");
stdout isn't an l-value.
Depends. On this system, it is. On systems where stdout is a macro, you're in trouble. If that's the case : stick with freopen()
"It may be an l-value on some systems" == "It's not a l-value as far as
clc is concerned". :-)
Of course, one could make a similar argument about "/dev/tty".
--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Irrwahn Grausewitz <ir*******@freenet.de> wrote:
# SM Ryan <wy*****@tango-sierra-oscar-foxtrot-tango.fake.org> wrote:
# >Irrwahn Grausewitz <ir*******@freenet.de> wrote:
# <snip>
# ># 1. I know of several systems that don't know anything about /dev/null.
# >
# >Apparently it meant something to the original poster.
# >If he had used "[15,4]:kumquat.rfd", I would've copied
# >"[15,4]:kumquat.rfd" whether I use RMS or not.
#
# Which would not have been the "correct way of opening stdout", too.
# Well, at least in the realm of comp.lang.c.
You just keep digging yourself deeper in a hole. You've snipped the part
where you piddle all over yourself, so it's not clear whether you think
an RMS file name is somehow more an ANSI C than a Unix one. Or whether
you don't know that freopen is ANSI C.
# ># 2. On the ones that do, writing to /dev/null is usually not the same
# ># as writing to whatever-stdout-happened-to-point-to on program
# ># startup.
# >
# >The original poster didn't want to write to whatever-stdout-happened-to-point-to.
Perhaps you could conclude that from his closing and reopening stdout.
Generally speaking, people who close files don't expect them to remain open.
# Umm. I cannot tell, he neither claimed he wanted, nor the opposite.
Actually you're trying to chase me out of comp.lang.c.
# "I hate it when people use the least appropriate quoting character
# in a C language group."
Want some cheese with that whine?
--
SM Ryan http://www.rawbw.com/~wyrmwif/
Quit killing people. That's high profile.
SM Ryan <wy*****@tango-sierra-oscar-foxtrot-tango.fake.org> wrote: Irrwahn Grausewitz <ir*******@freenet.de> wrote: # SM Ryan <wy*****@tango-sierra-oscar-foxtrot-tango.fake.org> wrote:
<snip># >If he had used "[15,4]:kumquat.rfd", I would've copied # >"[15,4]:kumquat.rfd" whether I use RMS or not. # # Which would not have been the "correct way of opening stdout", too. # Well, at least in the realm of comp.lang.c.
You just keep digging yourself deeper in a hole. You've snipped the part where you piddle all over yourself, so it's not clear whether you think an RMS file name is somehow more an ANSI C than a Unix one.
I cannot find any mention of specific file names in the standard.
What would make a file name "more an ANSI C one"? C&V, please.
Or whether you don't know that freopen is ANSI C.
If I wouldn't know I would've told you already.
# ># 2. On the ones that do, writing to /dev/null is usually not the same # ># as writing to whatever-stdout-happened-to-point-to on program # ># startup. # > # >The original poster didn't want to write to whatever-stdout-happened-to-point-to.
Perhaps you could conclude that from his closing and reopening stdout.
My crystal ball is broken. Too bad.
Generally speaking, people who close files don't expect them to remain open.
People who close a file associated with a standard stream should not
expect to get any other file successfully opened and associated to
that stream, not even using freopen. Your call to freopen might leave
you standing in the rain with only a closed stdout to cover your head.
<snip>
Actually you're trying to chase me out of comp.lang.c.
Huh?!? Actually, I'm trying to take over the whole abusenet and sell
it to MS. :>
<snip>
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc : http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc frequent answers: http://benpfaff.org/writings/clc. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Phil Powell |
last post by:
<?php
class FileRemoval {
var $fileNameArray, $isRemoved, $errorMsg = '';
function FileRemoval() { // CONSTRUCTOR
$this->fileNameArray = array();
$this->isRemoved = 0;
}
|
by: Paul Watson |
last post by:
How can I write lines to stdout on a Windows machine without having '\n'
expanded to '\r\n'.
I need to do this on Python 2.1 and 2.3+.
I see the msvcrt.setmode function. Is this my only path?...
|
by: Brian |
last post by:
'Ello,
I'm writing a perl script to spawn child processes to execute jobs.
The jobs are system calls. I use open(SYSCALL, "cmd |), to make the
system calls because I need the pipe so I can log...
|
by: Wesley Henwood |
last post by:
To capture output from python scripts run from a C++ app I've added the
following code at the beggening of the C++ app:
PyRun_SimpleString("import grabber");
PyRun_SimpleString("import sys");...
|
by: Paul Edwards |
last post by:
Is it permissible in C89 to do an "fclose(stdout)"
and then exit, or is the C runtime library allowed to
assume that stdout remains open and thus unconditionally
do an fclose itself?
Thanks. ...
|
by: David Mathog |
last post by:
A program of mine writes to a tape unit. Output can be either through
stdout or through a file opened with fopen(). When all the data is
transferred to tape the program needs to close the output...
|
by: Vincent Delporte |
last post by:
Hi
I'm a Python newbie, and would like to rewrite this Perl scrip
to be run with the Asterisk PBX:
http://www.voip-info.org/wiki/view/Asterisk+NetCID
Anyone knows if those lines are...
|
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= |
last post by:
Hello,
I have a C# application in which I start another process which produces
output to stdout and stderr. In fact, that process is the uSoft VS2005 C/C++
compiler itself! I would like to...
|
by: peterv6 |
last post by:
I'm having problems writing records to an output file. When I do it in Textpad running on Windows, the output file looks fine. When, however, I copy the script to a Linux machine and use the exact...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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...
|
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,...
| |