IBM Support

Carriage Returns Sometimes Removed in Qshell

Troubleshooting


Problem

Qshell redirection can remove the carriage return characters.

Resolving The Problem

Qshell utilities (such as Rfile) are not to blame for stripping the carriage return characters from user data. The carriage return characters are gone by the time that utility receives the input. The redirection operators (|<>) and the stdin, stdout, and stderr operations are the causes for why the carriage return characters are stripped. The secret to determining what is happening concerns the QIBM_DESCRIPTOR_STDxxx variables.

The following are the default values within Qshell:

QIBM_DESCRIPTOR_STDERR=CRLN=N
QIBM_DESCRIPTOR_STDOUT=CRLN=N
QIBM_DESCRIPTOR_STDIN=CRLN=Y

Qshell uses the C runtime to manage the stdout, stderr, and stdin operations. The C runtime has the capability to automatically add carriage return characters for output files and automatically remove carriage return characters for input files. This allows PC files (which typically contain carriage return characters) to be easily intermixed with IBM AIX files (which typically do not contain carriage return characters). The default environment variable values indicated above tell the C runtime to not insert carriage return characters (CRLN=N) for stdout and stderr, and to strip carriage return characters from stdin (CRLN=Y).

Example:

echo "line1\r\nline2\r\n" > outfile.txt

In this example, there is no stdin being read so the carriage return characters are preserved. The echo utility is writing to stdout, but nothing is being done with stdout. The file outfile.txt will have the carriage returns and line feeds preserved.

For the case of the command:

echo "line1\r\nline2\r\n" | Rfile -wbQ -c "CRTPF MIKSWENS/OUTFILE RCDLEN(10)" -C "CPYF FROMFILE(MIKSWENS/OUTFILE) TOFILE(*PRINT) OUTFMT(*HEX)" MIKSWENS/OUTFILE

the carriage return characters are stripped when the Rfile utility reads them from stdin.

The command:

echo "line1\r\nline2\r\n" | cat > outfile.txt

will have them stripped for the same reason. When the cat utility reads from stdin, the C runtime is going to automatically strip out the carriage return characters.

If you do not want any modifications done with carriage return characters, the environment variables should be changed to:

QIBM_DESCRIPTOR_STDERR=CRLN=N
QIBM_DESCRIPTOR_STDOUT=CRLN=N
QIBM_DESCRIPTOR_STDIN=CRLN=N

This indicates that stdin, stdout, and stderr should not do any special casing for carriage return characters. The C runtime does not have any other 'special' character handling; the carriage return handling is the only special case.

To return back to the example using Rfile:

export QIBM_DESCRIPTOR_STDERR=CRLN=N;
export QIBM_DESCRIPTOR_STDOUT=CRLN=N;
export QIBM_DESCRIPTOR_STDIN=CRLN=N;
echo "line1\r\nline2\r\n" | Rfile -wbQ -c "CRTPF MIKSWENS/OUTFILE RCDLEN(10)" -C "CPYF FROMFILE(MIKSWENS/OUTFILE) TOFILE(*PRINT) OUTFMT(*HEX)" MIKSWENS/OUTFILE

The above command will preserve the carriage returns and line feeds in the outfile and the spooled file.

Note that a similar issue sometimes arises when using redirection within Qshell; by default, the information being passed through stdout, stderr, and stdin is assumed to be text data. If binary data is being passed from one program to another through redirection, sometimes problems can occur. If that is the case, then the environment variable QIBM_DESCRIPTOR_TEXTDATA=N should be used to indicate that stdout, stdin, and stderr should be considered as binary data and, thus, no CCSID conversions will be done.

[{"Type":"MASTER","Line of Business":{"code":"LOB57","label":"Power"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SWG60","label":"IBM i"},"Platform":[{"code":"PF012","label":"IBM i"}],"Version":"6.1.0"}]

Historical Number

444829084

Document Information

Modified date:
18 December 2019

UID

nas8N1014470