GhostScript output to file - ghostscript

I use GhostScript to check for corrupt pdf files using the following command:
gswin64c.exe -o nul -sDEVICE=nullpage input.pdf
and I get the following output on the screen:
Processing pages 1 to 2.
Page 1
*****Error reading a content stream. The page may not be incomplete.
Page 2
*****Warning: File has insufficient data for an image.
*****This file had errors that were repaired or ignored.
This information is exactly what I need but I need this output in a text file as I will have to process a large number of files.
I tried to use the following command:
gswin64c.exe -o outputfile.txt -sDEVICE=txtwrite input.pdf
but the outputfile is empty.
How can I output these information into the file?

try redirecting stdout and stderr to files
eg.
gswin64c.exe -o nul -sDEVICE=nullpage input.pdf > output.txt 2> errors.txt

Related

NASM not working with /dev/stdout as output

My task is to create program generating some assembly code based on input on stdin, and output machine code on stdout.
My approach looks like this:
#!/bin/sh
if [ ! -f ./lc ]; then
gcc lc.c -o lc
fi
./lc | nasm /dev/stdin -fbin -o /dev/stdout
LC reads from stdin and outputs assembly code to stdout. Then i pipe assembly code to nasm that is reading from it's stdin. Finally I want to output machine code to /dev/stdout.
But, i get such error:
nasm:fatal: unable to open output file `/dev/stdout'
To verify /dev/stdout works, i checked it like that:
$ cat < /dev/stdin > /dev/stdout
test
test
What am I doing wrong? I tried sudoing, no effect. Is there some commandline switch for this application to output code to stdout? My best bet is avoid creating any temporary source files and work purely on streams.

How to display messages in a batch file when piping output?

I use a batch file below to concatenate video files using avidemux's cli executable. The reason why I pipe most of avidemux's output into 00_log.log is that its output is highly verbose and shoveling this to a text file appears to leave behind more helpful status or critical error messages displayed on the console. However, I'd like to see what file avidemux is working on at the time any error message pops up. Below, everything following ECHO is not displayed in the console.
Commenting or removing #echo off simply relays the ECHO lines below at the beginning of the batch job rather than alongside avidemux's console output, thus limiting its use.
#echo off
>00_log.log (
ECHO Joining foo.mp4
"C:\Program Files\Avidemux\avidemux_cli.exe" --load 1.mp4 --append 2.mp4 --output-format MP4v2 --save D:\foo.mp4
ECHO Joining foo2.mp4
"C:\Program Files\Avidemux\avidemux_cli.exe" --load 3.mp4 --append 4.mp4 --output-format MP4v2 --save D:\foo2.mp4
)
ECHO Job Done
#Pause
Simply redirect the avidemux_cli output to the log file, but not the rest.
So, use something like:
#echo off
ECHO Joining foo.mp4
"C:\Program Files\Avidemux\avidemux_cli.exe" --load 1.mp4 --append 2.mp4 --output-format MP4v2 --save D:\foo.mp4 >> 00_log.log
ECHO Joining foo2.mp4
"C:\Program Files\Avidemux\avidemux_cli.exe" --load 3.mp4 --append 4.mp4 --output-format MP4v2 --save D:\foo2.mp4 >> 00_log.log
ECHO Job Done
#Pause

Command line output not redirecting to file.

Very simple:
Open a console, and type
mkdir abc > output.txt
it creates a file called output.txt which is empty.
now repeat
mkdir abc > output.txt
This displays on the command window:
A subdirectory or file abc already exists
but does not output this to the txt.
Why?
You're redirecting standard output to your file; errors are typically reported on standard error, which is a different output stream. To redirect standard error, you can do this:
mkdir abc 2> output.txt
Or, if you want to combine both streams and direct them together:
mkdir abc 2>&1 >output.txt
More details here.
This will silently create a folder, if it exists or not.
mkdir abc 2>nul
Because the output of mkdir for the second call goes to stderr instead of stdout.

Reroute File Output to stdout in Bash Script

I have a script, wacaw (http://webcam-tools.sourceforge.net/) that outputs video from my webcam to a file. I am trying to basically stream that to some sort of display i.e vlc, quicktime, etc to get a "mirror" type effect.
Aside from altering the source code for wacaw, is there any way to force a script's file output to stdout so I can pipe it to something like vlc? Is it even possible to stream video like that?
Thanks for your help!
UPDATE: just to clarify:
running the wacaw script is formatted as follows:
./wacaw --video --duration 5 --VGA myFile
and it outputs a file myFile.avi. If I try to do a named pipe:
mkfifo pipe
./wacaw --video --duration 5 --VGA pipe
it outputs a file pipe.avi
You can use named pipes. You use mkfifo to create the pipe, hand that filename to the writing process and then read from that file with the other process. I have no idea if video in particular would work that way, but many other things do.
At least in bash you can do like this:
Original command:
write-to-file-command -f my-file -c
Updated command:
write-to-file-command -f >(pipe-to-command) -c
write-to-file-command will think >(pipe-to-command) is a write-only file and pipe-command will receive the file data on its stdin.
(If you just want the output to stdout you could do
write-to-file-command >(cat)
)
You may also try using tail -F myFile.avi:
# save stdout to file stdout.avi
man tail | less -p '-F option'
(rm -f myFile.avi stdout.avi; touch myFile.avi; exec tail -F myFile.avi > stdout.avi ) &
rm -f myFile.avi; wacaw --video --duration 1 --VGA myFile
md5 -q myFile.avi stdout.avi
stat -f "bytes: %z" myFile.avi stdout.avi
# pipe stdout to mplayer (didn't work for me though)
# Terminal window 1
# [mov,mp4,m4a,3gp,3g2,mj2 # ...]moov atom not found
#rm -f myFile.avi; touch myFile.avi; tail -F myFile.avi | mplayer -cache 8192 -
# Terminal window 2
#rm -f myFile.avi; wacaw --video --duration 1 --VGA myFile

How do I make wget properly quiet?

wget always echoes system values to the console, even when I specify -q (quiet) on the command line, e.g.:
C:\> wget -q http://www.google.com/
SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc
syswgetrc = C:\Program Files\GnuWin32/etc/wgetrc
C:\>
How do I make the noise stop?
that should work:
%> wget.exe parameters_here 1> NUL 2> NUL
Try adding a >NUL:
wget -q http://www.google.com/ >NUL
The more I rely on wget the more annoying these messages get. Appears to be a bug in wget version 1.11.4 (details here), a 2008 vintage that is still the "latest" binary for Windows. I prefer this work-around:
wget ...parameters... 2>>wgeterr.log
#akira 2>NUL makes the two lines go away, but I'm concerned what other error messages it may suppress. The following do not work: >NUL (output is to stderr) nor -q, nor -nv.

Resources