1

I am trying to to save output console in a text file in visual studio 2015 for a console c program. I right click the Project>Properties>Configuration Properties>Debugging>Command Argument and type there

> output.txt

to save the console in text file. But after I do this program doesn't ask for any inputs and the output console just keeps on with blinking underline. If I remove this, program starts working normally. When I check, file output.txt is there but without anything in it. It works when I give input from a file by adding <input.txt >output.txt while this is more desirable I prefer not to do as inputs are not visible in console.

When I try to run using 1&2>out.txtprogram executes , but the file is again empty.

I have tried using VS2019 same problem. I also tried changing platform from Win32 to All.

I even tried making batch file as follows

@ECHO OFF
for /r %%x in (*.c) do cl "%%x"
for /r %%x in (*.exe) do (
"%%x"
>"%%x".txt
clear
)
PAUSE

Any clue where I am doing it wrong ?

praxprog
  • 21
  • 5
  • If you are talking about a console program running on Windows, there is an answer [here](https://stackoverflow.com/a/15346929/645128) for doing that. It does not matter what dev environment or compiler that is used to generate `stdout`, Windows OS is what controls it. Short of writing code that [spawns a process that uses sockets and pipes](https://codereview.stackexchange.com/questions/162546/send-command-and-get-response-from-windows-cmd-prompt-silently), Windows shell redirection commands or batch scripts will have to do. – ryyker Aug 14 '20 at 13:57
  • yes, tried, no luck – praxprog Aug 14 '20 at 14:09
  • 2
    Do you want the prompts to appear on the console and the program output other than the prompts to end up in the file? If that is the case then you need two outputs: one for the prompts and one for the outputs. – cup Aug 14 '20 at 17:11
  • 1
    @praxprog Standard streams redirection works as expected with console programs, for example the default hello-world generated by the VS app wizard. It's hard to guess what you are doing differently without having any code to look at. See [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). – dxiv Aug 14 '20 at 21:28
  • @dxiv it is not working for any of codes I have , hence I didn't put the code. Anyway as of now I am doing it manually by copying output from console and pasting it in text. thank you. – praxprog Aug 16 '20 at 10:18
  • @praxprog If redirection doesn't work for the default hello-world console app generated by VS then you have a broken installation. If it does work for that app but not for your code then, again, show the code. – dxiv Aug 16 '20 at 22:38

0 Answers0