summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/satserver/util/Exec.java
blob: db59b0d433535303b6e3b47ce986a4203a97e2d2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package org.openslx.satserver.util;

import java.io.File;
import java.io.IOException;

public class Exec
{

	/**
	 * Run command, return exit status of process, or -1 on error
	 * 
	 * @param command Command and arguments
	 * @return exit code
	 */
	public static int sync( String... command )
	{
		return syncAt( "/", command );
	}

	public static int syncAt( String cwd, String... command )
	{
		ProcessBuilder pb = new ProcessBuilder( command );
		pb.directory( new File( cwd ) );
		Process p;
		try {
			p = pb.start();
			return p.waitFor();
		} catch ( IOException | InterruptedException e ) {
			return -1;
		}
	}

}