On a linux box I am making the following SVN import command:
svn import
--non-interactive
--trust-server-cert
--username username
--password password
-m "a message"
/path/to/local.zip
https://sub.domain.net/path/to/export.zip
When calling it from the command line myself it works without a problem.
However, if I make this call using a a Java command prompt then I receieve an error message that there are too many arguments in the import command.
Does anyone know what could be causing this?
Additional notes
-
If I copy and paste the Java generated svn
importcommand from my log file to the console then the import works as expected. -
I am able to use SVN
exportcommand from within Java without any problems -
I have tried using single
'quotes
Edit
The code to make these calls are as follows:
private void exportToSvn()
String command = String.format(
"svn import --non-interactive --trust-server-cert " +
"--username %s --password %s -m %s %s %s",
username, password, "\"a message\"", "/path/to/local.zip",
"https://sub.domain.net/path/to/export.zip"
);
command( command );
}
private void command( String... commands ) throws IOException, InterruptedException {
Runtime rt = Runtime.getRuntime();
for( String command : commands ){
Process pr = rt.exec( command );
BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
logger.debug( command );
String line;
while ( (line = input.readLine()) != null)
logger.debug("> " + line);
}
After an anonymous tip (the commenter deleted their comment before I caught their name) – I found that the problem lay with the quotes as they cannot be escaped within
Process(see this question).I found a work around for this was to include the quotes in
charformat instead: