Standard input stream redirection on debug
I am trying to port my project to QT and I need to use input stream redirection ( "<my_file_name") or run. I use the arguments field in project settings to set it up, but the problem is that whereas in the realease build it works, in the debug one, it actually takes "<my_file_name" as an argument and feeds it to the application.
More explicitly, following code:
using namespace std;
int main(int argc, char **argv)
for (int i = 0; i < argc; i++)
cout << string (argv[i]) << std::endl;
run with an argument "<some_existing_file.txt" does nothing on Release build and prints "<some_existing_file.txt" on Debug build.
I use Windows (tested on two different Win-based platforms), Qt 4.8.1 with MVSC2010 compiler and CDB debugger.
Any idea how to fix it so it? Thank you.
Have you tried putting a space between < and filename? I don't know how picky the Windows shell is about such things. Also, you're not putting quotes around <filename in Qt Creator, right? It works for me, but I'm on Linux.
Unfortunatelly, that run parameter (which is shared among build configurations) works for Release, so it's form is OK.
However, thanks for that Linux remark, now it seems more likely that the CDB causes the problem.
Ahhh, yes. That's probably it; the CDB command probably looks like
@cdb "yourprogram.exe <inputfile"@
Or the like, and CDB doesn't evaluate <inputfile as a redirection, but simply passes it as a parameter instead. I don't know how you can fix that, short of making the input an actual first class parameter to the program. Maybe read a file if it's provided, fall back to cin if not?
You are right, that really seems like a thing that could be causing the trouble.
There are of course many ways how to solve this problem, I have however hoped that I would not be required to change the code itself. I have only a little experience with usage of a command-line debugger - would anybody know some command that would tell the CDB to handle the argument as a stream redirection? Thanks.