Output redirection gives empty file?

Started by exif_inq, June 04, 2014, 02:07:58 PM

Previous topic - Next topic

exif_inq

I have a folder of pictures and I'd like to make a spreadsheet of their exif data. I tried the following code in the command line:

C:\Users\j\Desktop>exiftool -csv -filename -imagesize C:\Users\j\Desktop\test > output.csv

It creates a new file, but it's blank. When I add -k to the code, the window appears with all the relevant information about the pictures, so it's clearly not a problem reading the folder - it's just not writing it.

When I used -w txt with a single picture, it writes a file just fine. It's just when I'm using output redirection (the >), either with the folder or with a single picture, that I get a blank file in return.

I must be missing something obvious?




Phil Harvey

The redirection should work if you run the command inside a cmd.exe window.

The redirection is a function of the command shell (cmd.exe).

If you are executing this instead from inside some other software, you may need to handle the redirection yourself.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

exif_inq

Hi Phil, thanks for the response.

I am indeed running the command in a cmd.exe window; that's what makes this so baffling.

Phil Harvey

OK.  Try this:

echo "test" > out.txt

you should get a file called "out.txt" containing the word "test".

If this works, then try:

exiftool -echo "test2" > out2.txt

which should be equivalent (with a different output file so as not to get confused with the other one).

And if this works, then piping other exiftool commands should work too.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

exif_inq

The first command worked fine, but - once again, the second command created a blank file with nothing in it.

I'm beginning to suspect it might be something to do with the permissions on the computer - I'm running exiftool as an administrator, and it works perfectly fine for other commands, but perhaps there's something preventing it from writing in redirected files.

Thanks again for your help!

Phil Harvey

Wow, that's odd.

I can't see how it should matter what command you are using before the shell redirect, as long as the command was sending output to stdout, which ExifTool should be.

I'm at a bit of a loss here.

What version of Windows are you running?  Can you try this on another system?

- Phil

Edit:  Wait.  Can you confirm that this command works to print "test2" without the redirection?:

exiftool -echo "test2"
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

exif_inq

I tried using exiftool on another computer, using the exact same commands, and it worked perfectly. Both computers are running Windows 7 & in the same office, so it's still strange that one works and the other doesn't. But, at least it's working somewhere!

That command worked to print "test2" on the first computer, btw.

orax

And if you run the command with Powershell (or maybe cygwin) ? Same thing ?

echo "test1" >> a.txt
.\exiftool.exe -echo "test2" >> .\a.txt
cat .\a.txt
test1
test2

Phil Harvey

Quote from: exif_inq on June 06, 2014, 10:43:31 AM
I tried using exiftool on another computer, using the exact same commands, and it worked perfectly. Both computers are running Windows 7 & in the same office, so it's still strange that one works and the other doesn't. But, at least it's working somewhere!

That command worked to print "test2" on the first computer, btw.

OK.  So that only leaves something different in the settings between the two computers, which would point to something like you permission idea.  (Or, perhaps interference by some anti-virus software on the first computer?  -- I have seen before where some A.V. software locks the file and causes problems remotely similar to this.)

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

bobslost2

Hi - I have the same issue.  I think it is a strawberry perl/win7 64bit problem, not an Exiftool problem. See below:
F:\temp\play>type testit.pl
use strict;
use warnings;
print "this shoud be on stdout\n";

.\testit.pl > testit2.txt creates a zero length output file from the cmd shell shortcut installed with strawberry perl.  Same behaviour when I redirect exiftool output with this shell. The shortcut points to C:\Windows\SysWOW64\cmd.exe

if I use  C:\Windows\System32\cmd.exe no problems with redirection. So work-around:
exiftool.pl -a test.jpg > test.txt works fine from the shell created by the old [presumably 32bit] cmd.exe


Phil Harvey

Thanks for solving this question!

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).