Advertisement

Trouble passing arguments to other programs

Started by March 05, 2006 06:22 PM
10 comments, last by klems 18 years, 10 months ago
Organising a huge number of images is tiresome, and especially searching for duplicate images with different names. To alleviate this burden I decided to write a little utility that'd help me find images with identical sizes and SHA-1 hashes. Everything works great, except interaction with other applications. When the user passes "-q" to the application, output is supposed to be limited to only the filenames of possible duplicate files, discarding other diagnostic info. The purpose of this is to make it easier to use the utility with other applications. One might first run the application in its normal mode of operation, to find out if there are any possible dupes. If there are any, we might want to take some action. For example, opening all the suspects in Firefox, to confirm that they are indeed the same. This is where I run into trouble.
$ ./dupsearch -q Mai.Otome.HiME-Yuripack
 'Mai.Otome.HiME-Yuripack/Mai Hime - 079.gif' 'Mai.Otome.HiME-Yuripack/fanart_08_15.gif' 'Mai.Otome.HiME-Yuripack/Mai Hime - 013.jpg' 'Mai.Otome.HiME-Yuripack/mr_cg160.jpg'
As you can see, the application outputs all of the filenames in single quotes. If we copy this and paste it into the terminal, it works just fine:
$ mozilla-firefox 'Mai.Otome.HiME-Yuripack/Mai Hime - 079.gif' 'Mai.Otome.HiME-Yuripack/fanart_08_15.gif' 'Mai.Otome.HiME-Yuripack/Mai Hime - 013.jpg' 'Mai.Otome.HiME-Yuripack/mr_cg160.jpg'
However, this is a real bother, especially when there are lots of duplicate images. Therefore I'd do something like this:
$ mozilla-firefox `./dupsearch -q Mai.Otome.HiME-Yuripack`
This works fine - as long as none of the file or directory names contain any spaces. When there are spaces, it seems that the shell decides that each space denotes a new parameter, even when the space is part of a quoted word. This is a bit weird, seeing as it works fine with the same data if you copy and paste it. Does anyone have any suggestions about what I could do to fix this? I'm using bash on a Debian Unstable system.
try using double quotes like this:

$ mozilla-firefox `./dupsearch -q "image name with spaces.jpg"`

or if it doesnt work try:

$ mozilla-firefox "./dupsearch -q `image name with spaces.jpg`"

[Edited by - freenity on March 5, 2006 6:31:29 PM]
Advertisement
It still produces the same errors. The problem isn't passing directory names with spaces, that works just fine (using, for example, the technique you mentioned). Problems arise when images or subdirectories contain spaces.
Also, perhaps I should clarify a bit. The program takes a single directory name (not a list of files) as an argument, and then spits out the files that are suspected to be duplicate, so in my first code listing
./dupsearch -q Mai.Otome.HiME-Yuripack
is the command to execute, and
 'Mai.Otome.HiME-Yuripack/Mai Hime - 079.gif' 'Mai.Otome.HiME-Yuripack/fanart_08_15.gif' 'Mai.Otome.HiME-Yuripack/Mai Hime - 013.jpg' 'Mai.Otome.HiME-Yuripack/mr_cg160.jpg'
is the resulting output.
See if it works using a pipe

$ ./dupsearch -q Mai.Otome.HiME-Yuripack | mozilla-firefox
Quote: Original post by Will F
See if it works using a pipe

$ ./dupsearch -q Mai.Otome.HiME-Yuripack | mozilla-firefox
Didn't work either.
Firefox and most other utilities I'd consider using it with wants the files as arguments, not piped to stdin.
Have you tried using xargs? It allows passing arguments to a program in lots of weird and wonderful ways. You can check out how by the usual "man xargs", it should help you solve your problem.
Advertisement
Quote: Original post by Valderman
Didn't work either.
Firefox and most other utilities I'd consider using it with wants the files as arguments, not piped to stdin.


Didn't think it would.

I don't see any reason why the way you do it should fail, considering that it works if you copy/paste the output.

The only thing I can think of is to escape the spaces in the filenames rather than quoting the file. For example,

Mai.Otome.HiME-Yuripack/Mai Hime\ -\ 079.gif
is equivalent to
'Mai.Otome.HiME-Yuripack/Mai Hime - 079.gif'

but I doubt that'll make any difference.
I think i've found a possible cause of problem - using ./ between ` ` behaves differently than you are expecting it to. Then again, it's just a guess I don't know enough about the behavior of ` ` to competently say that this is the problem.

I wrote a hello world script in perl - take a look at the command line output from 2 attempts to invoke it

$ ./helloworldhelloworld$ `./helloworld `-bash: helloworld: command not found


I don't have access to a linux box right now, the above was tested on OS X - but I assume bash would behave the same on both.

In your case try adding the directory dupsearch resides in to your path and run it like this

$ mozilla-firefox `dupsearch -q Mai.Otome.HiME-Yuripack`




[Edited by - Will F on March 5, 2006 9:17:28 PM]
Hmm I made a similar test and I could use the ./
However, Im using firefox stable, and the only command line that works is

$ mozilla-firefox "myimage.gif"

$ mozilla-firefox "myimage.gif" "myimage2.gif"
gives me the usage message... (same without the quotes)

$ mozilla-firefox "myimage.gif myimage2.gif"
Error: Failed to send command: 509 internal error

Using single quotes gives the same results

I was checking the firefox command line options online, and I cant see that firefox support opening multiple files at all.
Im supprised you came as far as you did ^^

edit:
btw I got the same error as Will F with the `./test` but using echo `./test` worked
Quote: Original post by pulpfist
$ mozilla-firefox "myimage.gif" "myimage2.gif"
gives me the usage message... (same without the quotes)

$ mozilla-firefox "myimage.gif myimage2.gif"
Error: Failed to send command: 509 internal error


This page seems to suggest that this might work

$ mozilla-firefox "myimage.gif|myimage2.gif"

This topic is closed to new replies.

Advertisement