myfile.txt", but it wouldn't work." /> myfile.txt", but it wouldn't work." /> myfile.txt", but it wouldn't work."/>

Output redirection on Windows using the C language

1.9k views Asked by At

How do you redirect output in Windows using C?

I tried doing "./echo > myfile.txt", but it wouldn't work.

3

There are 3 answers

4
P0W On

Just use

echo.exe > myfile.txt

and

echo.exe >> myfile.txt to append to file

considering echo.exe is your executable

1
Joe DF On

Great Info here: http://www.robvanderwoude.com/redirection.php

Short Extract:

Redirection


command > file | Write standard output of command to file
command 1> file | Write standard output of command to file (same as previous)
command 2> file | Write standard error of command to file (OS/2 and NT)
command > file 2>&1 | Write both standard output and standard error of command to file (OS/2 and NT)
command >> file | Append standard output of command to file
command 1>> file | Append standard output of command to file (same as previous)
command 2>> file | Append standard error of command to file (OS/2 and NT)
command >> file 2>&1 | Append both standard output and standard error of command to file (OS/2 and NT)
commandA | commandB | Redirect standard output of commandA to standard input of commandB
commandA 2>&1 | commandB | Redirect standard output and standard error of commandA to standard input of commandB (OS/2 and NT)
command < file | command gets standard input from file
command 2>&1 | command's standard error is redirected to standard output (OS/2 and NT)
command 1>&2 | command's standard output is redirected to standard error (OS/2 and NT)


Ps. No need for slashes...

0
chux - Reinstate Monica On

It is the wrong slash for a Windows command shell. The OP used /, and they should have used \.

Use .\echo > myfile.txt