I know of the DOS command to redirect stdout
using this command, or some other method outside of coding it into the program, is there a way that I can have stdout go to the screen and a file???Code:C:> myprogram >info.txt
I know of the DOS command to redirect stdout
using this command, or some other method outside of coding it into the program, is there a way that I can have stdout go to the screen and a file???Code:C:> myprogram >info.txt
Well I'm new to C so I may be a little off. I think you could just write your own function that you pass text to, then you have it print it to the screen and write it to a file. There might be an easier way but that's all I know of.
-gunder
if (problem)
postcount++;
What you said would work perfectly, but please notice I said outside of coding it myself. I want to be able to do this for programs that I didn't write.
In *nix you'd use the tee command, but I don't know of a Windows console equivalent. But it's pretty easy to write one.
Code:#include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { FILE *fp; int c; if (argc != 2 || (fp = fopen(argv[1], "w")) == NULL) { perror (argv[1]); return EXIT_FAILURE; } while ((c = fgetc(stdin)) != EOF) { fputc (c, fp); fputc (c, stdout); } fclose(fp); return(0); } /* Usage: echo "blah" | thisprog.exe out.txt */
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
thanks Hammer. I'm not fully clear on the usage still. Would I be able to use that program to open another program and have its output go to both screen and file?
No, you use thisprog.exe to grab the output from another program and thisprog.exe will output to the screen and the file specified.
The syntax of the program as described by hammer is a little confusing. The syntax based on your need would be
C:> myprogram | thisprog.exe out.txt
The output of myprogram that goes to stdout will be piped ('|') into thisprog.exe. thisprog.exe then actually handles the output to the screen and to the file out.txt
Definition: Politics -- Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers
I've hit a snag....it works...but I can't use input anymore
You need to be more specific.Originally posted by Draco
I've hit a snag....it works...but I can't use input anymore
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
I put the program into the command line like WaltP said...it opened up the program and created a file for the output, but nothing I did on the keyboard would register as input, not even CTRL+C to force it to close.
Strange, works OK for me in a Windows Console.
Code:c:>junk2 | junk1 out.txt blah blah blah ^Z blah blah blah c:>type out.txt blah blah blah
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
As Hammer said, you need to be specific.Originally posted by Draco
I put the program into the command line like WaltP said...it opened up the program and created a file for the output, but nothing I did on the keyboard would register as input, not even CTRL+C to force it to close.
I put the program which program? into the command line like WaltP said...it opened up the program which program? and created a file for the output, but nothing I did on the keyboard would register as input, not even CTRL+C to force it to close. what is supposed to accept keyboard input?
It helps to tell us what the program before the pipe is supposed to do, and how that is interacting with the filter program....
***Lightbulb***
The program you are trying to run accepts keyboard input -- this is possibly the problem. When you pipe information, all the input is buffered and sent to the filter program in chunks. Therefore you can't write prompts to stdio. Output everything that must go to the screen to stderr with fprintf()
Definition: Politics -- Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers
I think you've hit the nail on the head, WaltP. I've been trying it with different programs I've made before I tried it on other programs, and all of mine use stdio..........
Ahh, the sweet smell of burning grey-matter (cough!)
Definition: Politics -- Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers