Author Topic: Input / output redirection before run  (Read 16918 times)

POLGIA0

  • Guest
Input / output redirection before run
« 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.

Offline xunxun

  • Almost regular
  • **
  • Posts: 187
Re: Input / output redirection before run
« Reply #1 on: December 18, 2010, 01:43:47 pm »
Project -- Set program's argument -- Select your target -- Program arguments
Regards,
xunxun

rajahks

  • Guest
Re: Input / output redirection before run
« Reply #2 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.

Offline vici

  • Single posting newcomer
  • *
  • Posts: 5
Re: Input / output redirection before run
« Reply #3 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.