file io trouble

  • Thread starter Merrill & Michele
  • Start date
M

Merrill & Michele

I can get files into my progs on the command line. For example if I wanted
a text file to act as if they were my keystrokes I would type the executable
name and then <text1.txt (I think that's how it went.) Is there an easy
way to capture the output to the console and redirect it to a file, say,
text2.txt ?

I'm not to the point in K&R where file io is discussed, and I found it too
confusing for me. Yet I need files in order to get through the earlier
material. MPJ
 
K

Kenneth Brody

Merrill said:
I can get files into my progs on the command line. For example if I wanted
a text file to act as if they were my keystrokes I would type the executable
name and then <text1.txt (I think that's how it went.) Is there an easy
way to capture the output to the console and redirect it to a file, say,
text2.txt ?
[...]

This is an O/S question, not a C language question.

However, if the program sends its output to stdout, many operating
systems and command interpreters allow ">filename" on the command
line to redirect stdout to the specified file. Ask your specific
O/S newsgroup for more details.

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:[email protected]>
 
D

Dan Pop

In said:
I can get files into my progs on the command line. For example if I wanted
a text file to act as if they were my keystrokes I would type the executable
name and then <text1.txt (I think that's how it went.) Is there an easy
way to capture the output to the console and redirect it to a file, say,
text2.txt ?

Try using the symmetrical construct, >text2.txt
I'm not to the point in K&R where file io is discussed,

Yeah, the thing is discussed on the second page of the I/O chapter.
But keep reading it in strict sequence.

Dan
 
J

John Bode

Merrill & Michele said:
I can get files into my progs on the command line. For example if I wanted
a text file to act as if they were my keystrokes I would type the executable
name and then <text1.txt (I think that's how it went.) Is there an easy
way to capture the output to the console and redirect it to a file, say,
text2.txt ?

If you have I/O redirection on the command line (and it sounds like
you do), you should be able to type >text2.txt to capture output.

prog <inputfile >outputfile
 
S

Stuart Gerchick

Merrill & Michele said:
I can get files into my progs on the command line. For example if I wanted
a text file to act as if they were my keystrokes I would type the executable
name and then <text1.txt (I think that's how it went.) Is there an easy
way to capture the output to the console and redirect it to a file, say,
text2.txt ?

I'm not to the point in K&R where file io is discussed, and I found it too
confusing for me. Yet I need files in order to get through the earlier
material. MPJ

to capture the output simply use >text2.txt.......isnt that pattern nice
 
S

suman kar

Merrill & Michele said:
I can get files into my progs on the command line. For example if I wanted
a text file to act as if they were my keystrokes I would type the executable
name and then <text1.txt (I think that's how it went.) Is there an easy
way to capture the output to the console and redirect it to a file, say,
text2.txt ?

I'm not to the point in K&R where file io is discussed, and I found it too
confusing for me. Yet I need files in order to get through the earlier
material. MPJ

Can try the following:
prompt$myprog > text2.txt
It redirects the output to stdout to the named file.
In case you are trying to append output to a file that already has
some information you can use
prompt$myprog >> text2.txt
If text2.txt does not exist it is created.

And if you are using some *nix system you might want to take a look at
http://www.ictp.trieste.it/~radionet/nuc1996/ref/shell/section3_7.html
HTH
Suman.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,148
Messages
2,570,838
Members
47,385
Latest member
Joneswilliam01

Latest Threads

Top