Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code Blocks redirecting input output

I'm new to code blocks, and I can't seem to get it to work with command line arguments of < input > output. Does anyone know how to?

I'm currently able to read a file passed from argv[1] but, the program doesnt automatically read the input from the given file nor does it right the output to the file output.

I'm aware it is on set program's arguments, my arguments line is: list.txt < input > output

After some research I saw a guy doing it like this: < ./input > ./output, seems like running a program to give the input and output, anyways, I've also tried that to no avail. Do I need to use file handlers to interact with it? It doesn't make sence, simple getchar() should read from the passing input file.

What am I missing here?

Thanks in advance

like image 205
d0pe Avatar asked Nov 08 '12 18:11

d0pe


People also ask

What character is used to redirect the output of a script to a file?

Input Redirection Just as the output of a command can be redirected to a file, so can the input of a command be redirected from a file. As the greater-than character > is used for output redirection, the less-than character < is used to redirect the input of a command.

What operator redirect output to another program?

Redirection is done using either the ">" (greater-than symbol), or using the "|" (pipe) operator which sends the standard output of one command to another command as standard input.

Why output is not showing in CodeBlocks?

go to view -> perspective -> and enable code::Blocks default, you can see your projects left side and down the build logs and messages etc. Save this answer. Show activity on this post. Save this answer.

How do you display output in code blocks?

Originally Answered: How do I get output screen for code written in C++ in codeblocks? Press F9 on your keyboard,it builds and runs your program in Codeblocks.


3 Answers

I have found a way how to do it in CB 13.12

Tools -> Configure Tools -> Add:

Name: whatever
Executable: C:\Windows\System32\cmd.exe
Parameters: /C ${TARGET_OUTPUT_BASENAME} exampleArg1 <inputFileRedirect.txt
Working Directory: ${TARGET_OUTPUT_DIR}

It basicaly launches windows console and passes Parameters to it. You can also assign keyboard shortcuts to these tools. The only disadvantage i can see is that the tools are not project specific.

like image 90
Aleš Koblížek Avatar answered Oct 13 '22 21:10

Aleš Koblížek


I've been working with Code::Blocks for some time now and just recently noted the same at least with Code::Blocks 12.11 in Windows. The redirections > and < do not work in the Project -> Set programs arguments...

A hackish solution is to do the execution in post-build step.

Right click project name -> Build options... -> Pre/post build steps -> Post-build steps:

cmd /C cd /D "bin\$(TARGET_NAME)\" & YourApplicationNameHere.exe >output.txt 2>errors.txt

And check the checkbox Always execute, even if target is up-to-date. Now hit Ctrl+F9 and the program is executed as a last step of the building process.

like image 32
user2678713 Avatar answered Oct 13 '22 21:10

user2678713


I think it is the problem of cb_console_runner.exe which launches your program in IDE. ConsoleRunner can not interpret redirection symbol. So, I add some code to the original code of codeblocks 13.12. Please copy linked file to [cb folder]. (Don't forget back-up the original.)

binary : http://limity.tistory.com/attachment/[email protected]

source code : http://limity.tistory.com/attachment/[email protected]

like image 1
Jehan Yoon Avatar answered Oct 13 '22 20:10

Jehan Yoon