Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run rsync command using runtime in java #29

Closed
ankita219819 opened this issue Apr 13, 2022 · 2 comments
Closed

Run rsync command using runtime in java #29

ankita219819 opened this issue Apr 13, 2022 · 2 comments
Labels

Comments

@ankita219819
Copy link

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
Copy link
Owner

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
Copy link
Author

Thank you for responding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants