Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0a1296e
Redirect stdout and stderr to COB_STDOUT_FILE and COB_STDERR_FILE
oguzcankirmemis Jun 22, 2026
f2974c4
Add test for stdout/stderr redirection
oguzcankirmemis Jul 7, 2026
bce45ee
Add changelogs, documentation for stdout/stderr redirection
oguzcankirmemis Jul 7, 2026
3baccc5
Fix cob_runtime_warning stderr when cobsetptr is not initialized yet
oguzcankirmemis Jul 7, 2026
7613e53
Fix cob_runtime_warning and cob_runtime_error to use default stderr i…
oguzcankirmemis Jul 7, 2026
e6d0122
Delete unnecessary include of common.h in common.c
oguzcankirmemis Jul 10, 2026
822c7eb
Rename stdout/stderr redirection test
oguzcankirmemis Jul 10, 2026
ea9954b
Default back to process stdout/stderr if parameter is empty
oguzcankirmemis Jul 10, 2026
66e4dae
Redirect stdin to COB_STDIN_FILE
oguzcankirmemis Jul 12, 2026
78ffb5e
Add test for stdin redirection
oguzcankirmemis Jul 12, 2026
bfb102d
Use getc to enable stdin redirection at termio.c
oguzcankirmemis Jul 12, 2026
1698600
Fix stdin redirection test
oguzcankirmemis Jul 12, 2026
7725087
Reset bdb_env stderr only if it configured and initialized in fileio.c
oguzcankirmemis Jul 12, 2026
181009a
Fix WIN32 cobc using libcob with stdin/stdout/stderr redirection
oguzcankirmemis Jul 12, 2026
586f85e
Add environment variables for redirection variables
oguzcankirmemis Jul 12, 2026
6967535
Make stdin/stdout/stderr redirection test platform agnostic
oguzcankirmemis Jul 12, 2026
fe56f38
Do not ignore return of fgets in redirection test
oguzcankirmemis Jul 12, 2026
d94cbfa
Update documentations/changelogs for stdin/stdout/stderr redirection
oguzcankirmemis Jul 13, 2026
6de4868
Refactor join_environment to use cob_settings_fileio in fileio.c
oguzcankirmemis Jul 15, 2026
889f5df
Adjust documentation/changelog
oguzcankirmemis Jul 16, 2026
4686881
Refactor variable declarations in common.c and run_misc.at
oguzcankirmemis Jul 16, 2026
0f40d43
Support SET ENVIRONMENT for redirection
oguzcankirmemis Jul 16, 2026
2ca1219
Use offsetof to determine config set
oguzcankirmemis Jul 17, 2026
f32e15c
Add tests for set environment redirection
oguzcankirmemis Jul 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ NEWS - user visible changes -*- outline -*-
already have a registered handler, allowing users to preserve their own
signal handlers during the initialization of the GnuCOBOL runtime.

** new runtime configurations: COB_STDIN_FILE, COB_STDOUT_FILE,
COB_STDERR_FILE. They allow redirection of stdin/stdout/stderr input/output
to a file. Alternatively, these configurations are also available as runtime
options which can be used to set them programmatically:
COB_SET_RUNTIME_STDIN_FILE, COB_SET_RUNTIME_STDOUT_FILE,
COB_SET_RUNTIME_STDERR_FILE.

** added multiple window functionality with new system function CBL_GC_WINDOW

** New system functions
Expand Down
6 changes: 6 additions & 0 deletions config/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

2026-07-07 Oğuzcan Kırmemiş <oguzcan.kirmemis@gmail.com>

* runtime.cfg: add runtime configurations COB_STDIN_FILE, COB_STDOUT_FILE,
COB_STDERR_FILE to allow redirection of stdin/stdout/stderr input/output
to given files

2025-11-19 Oğuzcan Kırmemiş <oguzcan.kirmemis@gmail.com>

* runtime.cfg: add runtime configuration COB_SIGNAL_REGIME to allow
Expand Down
24 changes: 24 additions & 0 deletions config/runtime.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,30 @@
# Default: false
# Example: COB_SET_DEBUG 1

# Environment name: COB_STDIN_FILE
# Parameter name: stdin_file
# Purpose: to define where COBOL stdin input should be read from
# Type: string (file) ; may use $-sequences
# Note: file is opened for read-only
# Default: stdin
# Example: STDIN_FILE ${HOME}/stdin.$$

# Environment name: COB_STDOUT_FILE
# Parameter name: stdout_file
# Purpose: to define where COBOL stdout output should go
# Type: string (file) ; may use $-sequences
Comment thread
oguzcankirmemis marked this conversation as resolved.
# Note: file is opened for append if name starts with "+"
# Default: stdout
# Example: STDOUT_FILE ${HOME}/stdout.$$

# Environment name: COB_STDERR_FILE
# Parameter name: stderr_file
# Purpose: to define where COBOL stderr output should go
# Type: string (file) ; may use $-sequences
# Note: file is opened for append if name starts with "+"
# Default: stderr
# Example: STDERR_FILE ${HOME}/stderr.$$

# Environment name: COB_SET_TRACE
# Parameter name: set_trace
# Purpose: to enable COBOL trace feature
Expand Down
6 changes: 6 additions & 0 deletions doc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

2026-07-07 Oğuzcan Kırmemiş <oguzcan.kirmemis@gmail.com>

* gnucobol.texi: document the new COB_SET_RUNTIME_STDIN_FILE,
COB_SET_RUNTIME_STDOUT_FILE and COB_SET_RUNTIME_STDERR_FILE runtime
options

2025-03-26 David Declerck <david.declerck@ocamlpro.com>

* gnucobol.texi: document the new --gentable option
Expand Down
20 changes: 20 additions & 0 deletions doc/gnucobol.texi
Original file line number Diff line number Diff line change
Expand Up @@ -1657,6 +1657,9 @@ enum cob_runtime_option_switch @{
COB_SET_RUNTIME_DISPLAY_PRINTER_FILE /* 'p' is FILE * */
COB_SET_RUNTIME_RESCAN_ENV /* rescan environment variables */
COB_SET_RUNTIME_DISPLAY_PUNCH_FILE /* 'p' is FILE * */
COB_SET_RUNTIME_STDIN_FILE /* 'p' is FILE * */
COB_SET_RUNTIME_STDOUT_FILE /* 'p' is FILE * */
COB_SET_RUNTIME_STDERR_FILE /* 'p' is FILE * */
Comment thread
oguzcankirmemis marked this conversation as resolved.
@};
COB_EXT_IMPORT void cob_set_runtime_option (enum cob_runtime_option_switch opt, void *p);
@end smallexample
Expand All @@ -1679,6 +1682,23 @@ cob_set_runtime_option (COB_SET_RUNTIME_DISPLAY_PUNCH_FILE,
(void*)((FILE*)myfd));
@end example

You are also able to redirect @code{ACCEPT} so that instead of stdin, it reads
from a file, by using:
@example
cob_set_runtime_option (COB_SET_RUNTIME_STDIN_FILE,
(void*)((FILE*)myfd));
@end example

Likewise, you could also redirect all @code{DISPLAY} output that would be
normally printed to stdout/stderr, including outputs directly coming from the
runtime, to a file by:
@example
cob_set_runtime_option (COB_SET_RUNTIME_STDOUT_FILE,
(void*)((FILE*)myfd));
cob_set_runtime_option (COB_SET_RUNTIME_STDERR_FILE,
(void*)((FILE*)myfd));
@end example

Another routine can be used to return the current value of the option.
@example
COB_EXT_IMPORT void *
Expand Down
16 changes: 16 additions & 0 deletions libcob/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@

2026-07-07 Oğuzcan Kırmemiş <oguzcan.kirmemis@gmail.com>

* common.c: add COB_STDIN_FILE, COB_STDOUT_FILE and COB_STDERR_FILE runtime
configurations for redirection of stdin/stdout/stderr to a file
Comment thread
oguzcankirmemis marked this conversation as resolved.
* common.h (cob_runtime_option_switch): add COB_SET_RUNTIME_STDIN_FILE,
COB_SET_RUNTIME_STDOUT_FILE and COB_SET_RUNTIME_STDERR_FILE enums
* common.c (cob_set_runtime_option, cob_get_runtime_option): extend for
COB_SET_RUNTIME_STDIN_FILE, COB_SET_RUNTIME_STDOUT_FILE and
COB_SET_RUNTIME_STDERR_FILE options
* coblocal.h (cob_settings): extend the setting to store FILE pointers
for stdin/stdout/stderr
* fileio.c: introduce cob_settings_fileio to trigger reset of settings
related configurations
* common.c, cobgetopt.c, coblocal.h, fileio.c, profiling.c, screenio.c,
termio.c: use stdin/stdout/stderr in cob_settings instead of global

2026-03-02 Fabrice Le Fessant <fabrice.le_fessant@ocamlpro.com>

* coblocal.h, common.c, profiling.c: rename is_test to cob_is_test
Expand Down
2 changes: 2 additions & 0 deletions libcob/cobgetopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ process_long_option (const int argc, char * const *argv, const char *optstring,
{
if (ambig_fallback)
{
/* TODO: Decide how to do stdout/stderr redirection here

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about here? Solve it similarly by adding an exported init function?

(and in examples below), or not at all */
fprintf (stderr, _("%s: option '%s%s' is ambiguous"),
argv[0], prefix, nextchar);
fputc ('\n', stderr);
Expand Down
12 changes: 12 additions & 0 deletions libcob/coblocal.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,16 @@ typedef struct __cob_settings {
unsigned int cob_core_on_error; /* signal handling and possible raise of SIGABRT
/ creation of coredumps on runtime errors */
char *cob_core_filename; /* filename for coredump creation */

char *cob_stdin_filename; /* Filename to redirect reads to stdin */
char *cob_stdout_filename; /* Filename to redirect writes to stdout */
char *cob_stderr_filename; /* Filename to redirect writes to stderr */
char *cob_stdin_filename_set; /* Current filename which is replacing stdin */
char *cob_stdout_filename_set; /* Current filename which is replacing stdout */
char *cob_stderr_filename_set; /* Current filename which is replacing stderr */
FILE *cob_stdin; /* FILE* to redirect reads to stdin */
FILE *cob_stdout; /* FILE* to redirect writes to stdout */
FILE *cob_stderr; /* FILE* to redirect writes to stderr */
} cob_settings;


Expand Down Expand Up @@ -469,6 +479,8 @@ COB_HIDDEN void cob_init_numeric (cob_global *);
COB_HIDDEN void cob_init_cconv (cob_global *);
COB_HIDDEN void cob_init_termio (cob_global *, cob_settings *);
COB_HIDDEN void cob_init_fileio (cob_global *, cob_settings *);
COB_HIDDEN void cob_settings_fileio (void);
COB_HIDDEN void cob_settings_termio (void);
COB_HIDDEN char *cob_get_filename_print (cob_file *, const int);
COB_HIDDEN char *cob_setup_filename (const cob_field *);
COB_HIDDEN void cob_init_reportio (cob_global *, cob_settings *);
Expand Down
Loading
Loading