Click here to Skip to main content
15,886,036 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to run rsync command with runtime in java.
In my A.class file 
```
@autowired
B bclass;

Public void testFileMove() 
{
String srcPath="src/main/resources/tmp/"
String destPath="src/main/resources/destTemp"
ReflectionUtils.setField(bclass, "tempSrc", srcPath) ;
ReflectionUtils.setField(bclass, "tempDest", destPath) ;
bclass.execute();
}

```

In my B.class

```
String tempSrc;
String tempDest;

Public void execute() 
{
 String runtimeCmd= "rsync -avR --remove-source-files "+tempSrc+"/ "+tempDest

Process process =Runtime.getRunyime.exec(runtimeCmd) ;
Int exitCode=process.waitFor() ;
Logger.Info(" Exit code is :"+exitCode) ;
}

```
I always get **error code as 23** for above code. 
When i give source and destination path as full path it works well. 
Eg:tempSrc=/home/usr/desktop/temp
tempSrc=/home/usr/desktop/destTemp

I need the path to be in resources folder of project so that its not specific to system path. With resources folder it become generic to project resource folder and this helps my build in bamboo as well. 


What I have tried:

I have also tried giving full path(/home/usr/desktop/myProject) to srcPath and destPath. It doesn't work.
Posted
Updated 13-Apr-22 21:57pm
Comments
Peter_in_2780 14-Apr-22 0:02am    
Adjust your command line to run rsync with -vv and capture the output somewhere.
That way you can see what directories and files it is trying to access.
Also, the EXIT CODE from 'man rsync' says
23 Partial transfer due to error
Maybe it is as simple as not having a writable destPath.
Shubham Sharma 5 14-Apr-22 2:20am    
The option -vv doesn't work. I was atleast figuring out to get the detailed log for this command when run using runtime.

1 solution

You can get the current directory path from the Java properties, via the key user.dir. Use that to construct the correct full path to your files. See Properties (Java Platform SE 7 )[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900