DrKLO/Telegram · error
%s: can't open stdout\n
Error message
%s: can't open stdout\n
What it means
In the Unix-style build with USE_FDOPEN, when no output file is named wrjpgcom writes to stdout and re-opens fd 1 in binary mode via fdopen(fileno(stdout), WRITE_BINARY). If fdopen returns NULL it prints `%s: can't open stdout` and exits EXIT_FAILURE. This is a stdout re-attach failure, not a disk error.
Source
Thrown at TMessagesProj/jni/mozjpeg/wrjpgcom.c:536
usage();
}
if ((outfile = fopen(argv[argn + 1], WRITE_BINARY)) == NULL) {
fprintf(stderr, "%s: can't open %s\n", progname, argv[argn + 1]);
exit(EXIT_FAILURE);
}
#else
/* Unix style: expect zero or one file name */
if (argn < argc - 1) {
fprintf(stderr, "%s: only one input file\n", progname);
usage();
}
/* default output file is stdout */
#ifdef USE_SETMODE /* need to hack file mode? */
setmode(fileno(stdout), O_BINARY);
#endif
#ifdef USE_FDOPEN /* need to re-open in binary mode? */
if ((outfile = fdopen(fileno(stdout), WRITE_BINARY)) == NULL) {
fprintf(stderr, "%s: can't open stdout\n", progname);
exit(EXIT_FAILURE);
}
#else
outfile = stdout;
#endif
#endif /* TWO_FILE_COMMANDLINE */
/* Collect comment text from comment_file or stdin, if necessary */
if (comment_arg == NULL) {
FILE *src_file;
int c;
comment_arg = (char *)malloc((size_t)MAX_COM_LENGTH);
if (comment_arg == NULL)
ERREXIT("Insufficient memory");
comment_length = 0;
src_file = (comment_file != NULL ? comment_file : stdin);
while ((c = getc(src_file)) != EOF) {View on GitHub (pinned to 45ab8f4308)
Solutions
- Redirect stdout to a real file: `wrjpgcom ... > out.jpg`.
- Use a TWO_FILE_COMMANDLINE build and name an explicit output file.
- Ensure fd 1 is a valid open writable descriptor before launching.
Example fix
// before wrjpgcom -comment hi in.jpg # stdout closed // after wrjpgcom -comment hi in.jpg > out.jpg
Defensive patterns
Strategy: validation
Validate before calling
#include <unistd.h>
/* ensure stdout (fd 1) is a valid writable descriptor */
if (fcntl(1, F_GETFD) == -1) { /* redirect or name an output file */ } Prevention
- Redirect stdout to a file: wrjpgcom ... > out.jpg.
- Use a TWO_FILE_COMMANDLINE build with a named output.
- Never launch with fd 1 closed.
When it happens
Trigger: Running wrjpgcom with stdout closed or an invalid fd 1 (e.g. launched with stdout>&- or from a process that closed fd 1), under a USE_FDOPEN build.
Common situations: Daemon/JNI spawn that did not wire stdout, `>&-` redirection in a shell wrapper, or piping into a command that immediately closes its stdin.
Related errors
- %s: can't open stdin\n
- %s: can't open %s
- Comment text may not exceed %u bytes
- %s: can't open %s\n
- %s: must name one input and one output file\n
AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14).
Data as JSON: /api/errors/4e393ce43ce96126.
Report an issue: GitHub.