fracpete / rsync4j

Simple Java wrapper for rsync for Linux, OSX and Windows.
https://fracpete.github.io/rsync4j/
GNU General Public License v3.0
115 stars 29 forks source link

Run rsync command using runtime in java #29

Closed ankita219819 closed 2 years ago

ankita219819 commented 2 years ago

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.

fracpete commented 2 years ago

This isn't a question about rsync4j, but a general rsync question.

If you use relative paths, you have to ensure that your current working directory (System.getProperty("user.dir")) and your relative paths resolve to the paths that you want to synchronize.

ankita219819 commented 2 years ago

Thank you for responding