May 18, 2011 at 9:22am UTC
i want to put all the contains returned by system("dir") into a text file.
and also i wanna avoid the output on the screen (console program) when i use the system().
and please don't suggest system("cls").
how can i do this.
May 18, 2011 at 10:05am UTC
i know how to use _findfirst and _findnext and i can also create my own program to list dirs.
but i want to pipe the buffers and etc returned by the system function into the text file.
i am asking this question because not only i wanna use system("dir") but i will use this on other commands.
don't worry about security i use system() when i am in hurry and not doing any important work.
May 18, 2011 at 10:15am UTC
@kbw, our posts are clashing.. :P
But you can write to file whatever is returned from these functions. I mean you can achieve everything what a system("dir") can for you.
Although, i have no idea how will you catch anything returned by system().
Last edited on May 18, 2011 at 10:18am UTC
May 18, 2011 at 11:56am UTC
Here I go again with can't. You can't.
system() spawns the shell, which runs the command. The command in this case, isn't even an external program, it's a shell directive.
You can control stdin/stdout on the programs that your app spawns and you can deal with redirection yourself, but not by using system().
I've never seen system() used in any commercial app and I suggest you consider not using it at all.