Discussion:
[exec] Executed command can't open file argument
(too old to reply)
Mark Trolley
2018-05-01 19:23:12 UTC
Permalink
(Sorry if this message appears twice. I sent it once before subscribing and
haven't seen it appear in the archives so I assume it wasn't accepted.)

I’m trying to use Apache Commons Exec to run the AtomicParsley tagging
program, but execution fails with an error that the input file doesn’t
exist. If I dump the command line arguments then manually execute
AtomicParsley with the exact same arguments it succeeds. I know the file at
the given path is readable because I tested reading it directly in my Java
code and it succeeds. The error that the file doesn’t exist only happens
when I use Commons Exec.

Here is a snippet of my code:

CommandLine cmdLine = new CommandLine("AtomicParsley");
cmdLine.addArgument("${file}");
cmdLine.addArgument("--overWrite");
cmdLine.addArgument("--artwork");
cmdLine.addArgument("REMOVE_ALL");
Map<String, String> map = new HashMap<String, String>();
map.put("file”, path.toFile().getAbsolutePath());
cmdLine.setSubstitutionMap(map);
ExecuteWatchdog watchdog = new ExecuteWatchdog(60 * 1000);
Executor executor = new DefaultExecutor();
executor.setExitValue(0);
executor.setWatchdog(watchdog);
try {
executor.execute(cmdLine);
} catch (IOException ioe) {
System.err.println("Error removing artwork");
ioe.printStackTrace();
}

If I use a script to dump out the arguments I see they are correct:

"/Users/mtrolley/testing_mp4/Futurama - S05E01.mp4"
--overWrite
--artwork
REMOVE_ALL

If I use those arguments to manually run AtomicParsley it works:

$ AtomicParsley "/Users/mtrolley/testing_mp4/Futurama - S05E01.mp4”
--overWrite --artwork REMOVE_ALL
No changes.
$

When I run the same command using exec:
AtomicParsley error: can't open "/Users/mtrolley/testing_mp4/Futurama -
S05E01.mp4" for reading: No such file or directory

Thanks in advance for any help.
Guang Chao
2018-05-02 14:35:39 UTC
Permalink
Post by Mark Trolley
(Sorry if this message appears twice. I sent it once before subscribing and
haven't seen it appear in the archives so I assume it wasn't accepted.)
I’m trying to use Apache Commons Exec to run the AtomicParsley tagging
program, but execution fails with an error that the input file doesn’t
exist. If I dump the command line arguments then manually execute
AtomicParsley with the exact same arguments it succeeds. I know the file at
the given path is readable because I tested reading it directly in my Java
code and it succeeds. The error that the file doesn’t exist only happens
when I use Commons Exec.
CommandLine cmdLine = new CommandLine("AtomicParsley");
cmdLine.addArgument("${file}");
cmdLine.addArgument("--overWrite");
cmdLine.addArgument("--artwork");
cmdLine.addArgument("REMOVE_ALL");
Map<String, String> map = new HashMap<String, String>();
map.put("file”, path.toFile().getAbsolutePath());
cmdLine.setSubstitutionMap(map);
ExecuteWatchdog watchdog = new ExecuteWatchdog(60 * 1000);
Executor executor = new DefaultExecutor();
executor.setExitValue(0);
executor.setWatchdog(watchdog);
try {
executor.execute(cmdLine);
} catch (IOException ioe) {
System.err.println("Error removing artwork");
ioe.printStackTrace();
}
"/Users/mtrolley/testing_mp4/Futurama - S05E01.mp4"
--overWrite
--artwork
REMOVE_ALL
$ AtomicParsley "/Users/mtrolley/testing_mp4/Futurama - S05E01.mp4”
--overWrite --artwork REMOVE_ALL
No changes.
$
Apologize, I just wish to cover the basics. Have you check which user you
use to execute the Java program? And could you kindly check if that user
has the rights to execute AtomicParsley? Maybe set file permission to 755
or something.
Post by Mark Trolley
AtomicParsley error: can't open "/Users/mtrolley/testing_mp4/Futurama -
S05E01.mp4" for reading: No such file or directory
Thanks in advance for any help.
--
Guang <http://javadevnotes.com/java-copy-array>
Mark Trolley
2018-05-03 16:18:15 UTC
Permalink
I'm not sure how to respond to my own thread so I am hoping sending a
reply to my own sent message will do it.

I experimented and discovered the problem is in the spaces in the
filename argument. If the file is renamed to not have spaces the
execution succeeds. However, this doesn't work for my usecase because
I want to parse the filename for information to get metadata I'll use
later.

@Guang Chao - I can't respond directly to your message because I
didn't receive it in my mail, but I changed the command being executed
to "/usr/bin/whoami" and confirmed that the Java code is running as my
user, so there is no permission issue.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@commons.apache.org
For additional commands, e-mail: user-***@commons.apache.org
sebb
2018-05-03 20:34:04 UTC
Permalink
Post by Mark Trolley
I'm not sure how to respond to my own thread so I am hoping sending a
reply to my own sent message will do it.
I experimented and discovered the problem is in the spaces in the
filename argument. If the file is renamed to not have spaces the
execution succeeds. However, this doesn't work for my usecase because
I want to parse the filename for information to get metadata I'll use
later.
It may be that quotes are being added to the parameter - I assume the
file name does not have quotes.

Quoting is necessary for protecting spaces on a shell command-line,
but not when the parameters are being passed directly to a program as
separate parameters.

It would be useful to know if the AtomicParsley app puts quotes around
file names in error messages.

I seem to remember some issues with inappropriate quoting of
parameters a long time ago, but I thought they had been resolved.
Maybe not. Or maybe the issue is with the substitution map processing
- can you try without that?

Might also be worth trying the command-line approach.

BTW for checking parameters a script is not ideal because the shell
may get involved.

It's easy enough to write a Java program to print out its parameters
(or use one of the scripting languages).
That should behave closer to the AtomicParsley app.
Post by Mark Trolley
@Guang Chao - I can't respond directly to your message because I
didn't receive it in my mail, but I changed the command being executed
to "/usr/bin/whoami" and confirmed that the Java code is running as my
user, so there is no permission issue.
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@commons.apache.org
For additional commands, e-mail: user-***@commons.apache.org
Mark Trolley
2018-05-03 21:35:27 UTC
Permalink
Post by sebb
It may be that quotes are being added to the parameter - I assume the
file name does not have quotes.
Quoting is necessary for protecting spaces on a shell command-line,
but not when the parameters are being passed directly to a program as
separate parameters.
This lead me to the solution, I had to use addArgument with
handleQuoting set to false and it started working. Thanks everyone for
your help.
Post by sebb
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@commons.apache.org
For additional commands, e-mail: user-***@commons.apache.org
sebb
2018-05-04 06:49:10 UTC
Permalink
Post by Mark Trolley
Post by sebb
It may be that quotes are being added to the parameter - I assume the
file name does not have quotes.
Quoting is necessary for protecting spaces on a shell command-line,
but not when the parameters are being passed directly to a program as
separate parameters.
This lead me to the solution, I had to use addArgument with
handleQuoting set to false and it started working. Thanks everyone for
your help.
Thanks for letting us know it's been solved.
Post by Mark Trolley
Post by sebb
---------------------------------------------------------------------
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@commons.apache.org
For additional commands, e-mail: user-***@commons.apache.org

Martin Gainty
2018-05-03 21:28:26 UTC
Permalink
Mark-


1)get an OS that supports spaces in filenames

2)OR use quote to delimit file name e.g.
"file name.ext"
https://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/filequot.htm


HTH
Martin
______________________________________________



________________________________
From: Mark Trolley <***@gmail.com>
Sent: Thursday, May 3, 2018 11:30 AM
To: Martin Gainty
Subject: Re: [exec] Executed command can't open file argument

You're absolutely right in that it was the spaces in the filename. If I rename the file without spaces it works correctly. By the way I am running this on a Mac, though I didn't think that would make any difference.

Is there any workaround other than renaming the file to get it to handle spaces in the name? I need them formatted that way because I parse the name to detect the show name, season number, and episode number to look up metadata.

On Tue, May 1, 2018 at 5:35 PM, Martin Gainty <***@hotmail.com<mailto:***@hotmail.com>> wrote:


MG>please see below

MG>some file systems cannot read either long filenames or filenames with spaces
MG>what happens if you shorten up testing_mp4 to TESTIN~1 and shorten Futurama - S05E01.mp4 to Futurama.mp4 ?

MG>check acl/cacls permissions
MG>for the user that you use to run AtomicParsley has permissions to read
MG>/Users/mtrolley/testing_mp4/Futurama - S05E01.mp4 ?

Thanks in advance for any help.
Loading...