473,378 Members | 1,469 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,378 software developers and data experts.

stdin stderr

I created a program which takes input from stdin like:
myprogram <commandlist.txt

I want if I not redirect stdin (with <file) then my program return a error
message and terminate
I do not want to waiting for input from keyboard

Is this possible? How?

How can I send strings to stderr? (e.g. to stdout I send strings with
printf())

Thanks
Jul 19 '05 #1
6 7976
> > I created a program which takes input from stdin like:
myprogram <commandlist.txt

I want if I not redirect stdin (with <file) then my program return a error message and terminate
I do not want to waiting for input from keyboard

Is this possible? How?

How can I send strings to stderr? (e.g. to stdout I send strings with
printf())

Thanks

Maybe you could check if any command line arguments where passed (i.e argc

1). This is a bit of a weak way to check, but its the only one I can think
of.


no. argc ==1 <file is not a parameter, is a redirection
to stdin

thanks for second question
Jul 19 '05 #2
"<- Chameleon ->" <ch******@hotmail.NOSPAM.com> wrote in message
news:be**********@nic.grnet.gr...
I created a program which takes input from stdin like:
myprogram <commandlist.txt

I want if I not redirect stdin (with <file) then my program return a error message and terminate
I do not want to waiting for input from keyboard

Is this possible? How?

How can I send strings to stderr? (e.g. to stdout I send strings with
printf())

Thanks

Maybe you could check if any command line arguments where passed (i.e argc
1). This is a bit of a weak way to check, but its the only one I can think of.


no. argc ==1 <file is not a parameter, is a redirection
to stdin

thanks for second question

Sorry, I misread... sunday night blues!
-Samuele
Jul 19 '05 #3
"<- Chameleon ->" <ch******@hotmail.NOSPAM.com> wrote in message news:<be**********@nic.grnet.gr>...
I created a program which takes input from stdin like:
myprogram <commandlist.txt

I want if I not redirect stdin (with <file) then my program return a error
message and terminate
I do not want to waiting for input from keyboard

Is this possible? How?
C++ does not provide a means for doing this. Just take the filename as
a command-line argument and open the file inside your program.

(On Linux, there are system functions to determine whether standard
input is coming from a terminal [i.e., a user, not a file]. Other
systems may have similar capabilities. If you *really* want to do this
[but you really shouldn't], ask a newsgroup related to your system.)
How can I send strings to stderr? (e.g. to stdout I send strings with
printf())


C I/O routines are listed here:

<http://dinkumware.com/htm_cpl/stdio.html>

Take particular note of the ones that begin with the letter 'f'. Note
that stderr is a FILE *.

Note: Use puts/fputs for "sending strings" instead of printf/fprintf
whenever possible. See the following:

<http://groups.google.com/groups?selm=3E8DA58F.6020303%40newsguy.com>
<http://www.securityfocus.com/guest/3342>

Other note: In C++, prefer C++ iostreams over C I/O functions unless
you have good reason not to do so. They're safer and more extensible
(albeit a little slower, but you shouldn't be concerned with that at
this point).

Also, get a good C++ book, like Koenig and Moo's "Accelerated C++" --
it's easier to use and more patient than this newsgroup. :)

- Shane
Jul 19 '05 #4
> I want if I not redirect stdin (with <file) then my program return a error
message and terminate
I do not want to waiting for input from keyboard

Is this possible? How?
Try look isatty function. However it's not a C/C++ standard function but it
is at least
in gcc and VC++ (_isatty in latter case).

How can I send strings to stderr? (e.g. to stdout I send strings with
printf())


In C I could use: fprintf(stderr, "evil comes\n");
In C++ it may be: cerr << "somthing happend" << endl;

Look also perror function.

--
Sergey Tursanov _g***@hippo.ru
to send me an email replace '_' from the address above.
Jul 19 '05 #5
> I created a program which takes input from stdin like:
myprogram <commandlist.txt

I want if I not redirect stdin (with <file) then my program return a error
message and terminate
I do not want to waiting for input from keyboard

Is this possible? How?

How can I send strings to stderr? (e.g. to stdout I send strings with
printf())

Thanks


my approach now is to write something in the end of stdin (a ending header)
is this possible with C/C++? How?
Jul 19 '05 #6
"<- Chameleon ->" <ch******@hotmail.NOSPAM.com> wrote in message news:<be**********@nic.grnet.gr>...
my approach now is to write something in the end of stdin (a ending header)
is this possible with C/C++? How?


How (or why) would you propose to *write* something to *standard
input*, since "input" means "for reading" (contrast with "output")?
stdin is for reading, not for writing.

This means, incidentally, that the answer to your question is "no."

If you meant something else, please rephrase your question.

- Shane
Jul 19 '05 #7

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

Similar topics

0
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...
4
by: Jan Knop | last post by:
Hello I am writing a Windows application where I need to redirect stdin, stdout and stderr from Python. to my application Is it a simple way of do it ? Has anyone done it using Winsock ?
1
by: Vincent Touquet | last post by:
Hi, In a project where I have embedded Python in a C++ application, I have the need to replace what Python considers to be stdin, stdout and/or stderr. In sysmodule.c in the Python sources, I...
0
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...
8
by: Dan Stromberg | last post by:
Is there a way of setting O_DIRECT on a preexisting file like sys.stdin? Does C allow this sort of thing? Thanks!
23
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...
6
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...
11
by: David Warner | last post by:
Greetings! I need to write some C code that will decide between either reading from stdin or take a file name from argv and process it. The program needs to work like all of the typical unix...
8
by: Christoph Haas | last post by:
Hi... I encountered a problem that - according to my google search - other people have found, too. Example code: import sys for line in sys.stdin: print line Running this code in Python...
2
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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 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.