Environment: Windows 10 (Java) -> Windows 10 (PowerShell and C#) Java: 1.8.0_252
Trying to remotely execute a C# program via PowerShell from Java. Seem to be having issues with the path. The C# program is in a subdirectory under a shared drive.
import java.io.*;
public class CallCSharp {
public static void main(String[] args) {
try {
ProcessBuilder builder = new ProcessBuilder("powershell.exe", "/c",
"\\SharedDrive\\Data\\Bin\\Program.exe \\\\10.1.1.1 -u user -p password");
builder.redirectErrorStream(true);
Process p = builder.start();
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while (true) {
line = r.readLine();
if (line == null) {
break;
}
System.out.println(line);
}
} catch (Exception e){
e.printStackTrace();
}
}
}
The error returned is
The term '\SharedDrive\Data\Bin\Program.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
The path is correct and the C# program can be run successfully.
Suspect I am not formatting the ProcessBuilder call correctly.
\\\\ShareDrivethen?