How to run shell scripts in Java

preview_player
Показать описание
Running shell scripts from inside Java code using ProcessBuilder in a thread. This solution works on Windows (.bat file) and Unix (.sh file) - running example in both environments in video.

► Social Media

► Music
Creative Commons — Attribution 3.0 Unported — CC BY 3.0
Рекомендации по теме
Комментарии
Автор

Thanks a lot man for the complete implementation ... great work

SCool
Автор

I have two pc. PC-1 and PC-2 and I have same script in PC 2 and I want to run the program in PC-1. How i will do but I have username password ip address and file location. These things. How i will do please please help me.

DurgeshKumar-ijhb
Автор

Hi
I'm trying out something here
I'm trying to run rsync command with runtime in java.
In my A.class file
```
@autowired
B bclass;

Public void testFileMove()
{
String
String
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 ;
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.



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.

Can someone help me

ankitagupta
visit shbcf.ru