Hey all new to Powershell so here goes.
I am wanting to take the code below and convert it into java so that I do not have to run a separate Powershell script outside my program when its running.
[string] $wspaceDir = "C:\Temp\loadDir",
[string] $scmLoc = "C:\Local Apps\IBM\SDP\scmtools\eclipse\scm.exe",
[string] $portNumForDaemon = "61938"
start-job -scriptblock {
Set-Location "$($args[1])"
Write-Host "Starting Daemon on port $args[2]" -foregroundcolor "Yellow"
&"$($args[0])" "daemon" "start" "$($args[1])" "--port" $args[2]
} -ArgumentList $scmLoc, $wspaceDir, $portNumForDaemon
And so far the info I have on what its doing above is running that in a separate thread in order to carry on and not wait on it to finish.
In java I have tried to mimic that:
private static String portNumForDaemon = "61938";
private static String scmLoc = "C:\\Local Apps\\IBM\\SDP\\scmtools\\eclipse\\scm.exe";
private static String wspaceDir = "C:\\TempRQM";
public static void blah() {
ExecutorService pool = Executors.newSingleThreadExecutor();
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command("cmd.exe", "/c", scmLoc + " daemon start " + wspaceDir + " --port " + portNumForDaemon);
try {
Process process = processBuilder.start();
System.out.println("process ping...");
ProcessReadTask task = new ProcessReadTask(process.getInputStream());
List<String> supplierNames = new ArrayList<String>();
Future<list<string>> future = pool.submit(task);
// no block, can do other tasks here
System.out.println("process task1...");
System.out.println("process task2...");
List<string> result = future.get(5, TimeUnit.SECONDS);
for (String s : result) {
System.out.println(s);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
pool.shutdown();
}
}
private static class ProcessReadTask implements Callable<list<string>> {
private InputStream inputStream;
public ProcessReadTask(InputStream inputStream) {
this.inputStream = inputStream;
}
@Override
public List<string> call() {
return new BufferedReader(new InputStreamReader(inputStream))
.lines()
.collect(Collectors.toList());
}
}
And as much as I would like to run this I am getting an error on all the implements Callable< list >, Future< list >.
I am not sure if I am doing this correctly or not. I don't even know for sure that's equivalent to what the Powershell is doing?
And Powershell/Java guru able to help me out would be great!