Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: POLGIA0 on December 18, 2010, 09:44:58 am

Title: Input / output redirection before run
Post by: POLGIA0 on December 18, 2010, 09:44:58 am
Hi, I'm not a professional programmer and I use CB to run Fortran code. Can someone suggest how to make input / output redirection in CB? More specifically I would like to read from a file instead than type input. From the console, this can be done with the console comand: program_name.exe< inputfilename. It should be possible to redirect input running the program by CB but I'm cannot find this possibility in the settings. Thanks in advance for your help.
Title: Re: Input / output redirection before run
Post by: xunxun on December 18, 2010, 01:43:47 pm
Project -- Set program's argument -- Select your target -- Program arguments
Title: Re: Input / output redirection before run
Post by: rajahks on April 29, 2013, 05:56:01 pm
I want to do something similar i.e redirect the contents of a file to the program so that rather than reading from stdin the program reads from the redirected input. Equivalent to pgm.exe < input

Is it possible to do this in code blocks ??

If  <input.txt is entered in the 'Program Arguments window:' it appears as a string in the char*argv[] parameter of main(..) function.

Thanks in advance.
Title: Re: Input / output redirection before run
Post by: vici on January 19, 2026, 07:43:13 am
Project -- Set program's argument -- Select your target -- Program arguments

Your solution passes the string "<input.txt" to argv[0], so in the program, one needs to use fopen, fget... And that string as argument to fscaf() will fail, because of the redirection character at the beginning.

OP (and me as well) want to use only scanf to read the data, and not care about the file name.

Problem still unanswered, using Codeblocks 25.03 under Windows 10.