use of org.vcell.util.exe.Executable in project vcell by virtualcell.
the class VisitSupport method launchVisTool.
public static void launchVisTool(File visitExecutable, SimulationDataSetRef simulationDataSetRef) throws IOException, ExecutableException, URISyntaxException, InterruptedException {
if (OperatingSystemInfo.getInstance().isMac()) {
launchVisToolMac(visitExecutable);
return;
} else if (OperatingSystemInfo.getInstance().isLinux()) {
launchVisToolLinux(visitExecutable);
return;
}
// MSWindows
if (visitExecutable == null) {
visitExecutable = ResourceUtil.getExecutable(VISIT_EXEC_NAME, false);
if (visitExecutable == null || !visitExecutable.exists() || !visitExecutable.isFile()) {
throw new IOException("visit executable not found, " + visitExecutable.getAbsolutePath());
}
}
VCellConfiguration.setFileProperty(PropertyLoader.visitExe, visitExecutable);
File visMainCLI = getVisToolPythonScript();
if (!visMainCLI.exists() || !visMainCLI.isFile()) {
throw new IOException("vcell/visit main python file not found, " + visMainCLI.getAbsolutePath());
}
if (lg.isInfoEnabled()) {
lg.info("Starting VCellVisIt as a sub-process");
}
//
// get existing environment variables and add visit command and python script to it.
//
Map<String, String> envVariables = System.getenv();
ArrayList<String> envVarList = new ArrayList<String>();
for (String varname : envVariables.keySet()) {
String value = envVariables.get(varname);
envVarList.add(varname + "=" + value);
}
String siteName = ResourceUtil.getSiteName();
File vcellHomeVisFolder = new File(new File(ResourceUtil.getVcellHome(), "Vis"), siteName);
if (!vcellHomeVisFolder.exists()) {
if (!vcellHomeVisFolder.mkdirs()) {
throw new IOException("Cannot create directory " + vcellHomeVisFolder.getCanonicalPath());
}
}
// FileUtils.copyDirectoryShallow(visMainCLI.getParentFile(), vcellHomeVisFolder);
FileUtils.copyDirectory(visMainCLI.getParentFile(), vcellHomeVisFolder, true, new VisitFolderFileFilter());
File vcellHomeVisMainCLI = new File(vcellHomeVisFolder, visMainCLI.getName());
vcellHomeVisMainCLI.setExecutable(true);
envVarList.add("visitcmd=" + /*"\""+*/
visitExecutable.getPath());
envVarList.add("pythonscript=" + vcellHomeVisMainCLI.getPath().replace("\\", "/"));
// envVarList.add("pythonscript="+visMainCLI.toURI().toASCIIString());
final String[] cmdStringArray = new String[] { "cmd", "/K", "start", "\"\"", visitExecutable.getPath(), "-cli", "-uifile", vcellHomeVisMainCLI.getPath().replace("\\", "/") };
if (simulationDataSetRef != null) {
File simDataSetRefFile = new File(ResourceUtil.getLocalVisDataDir(), "SimID_" + simulationDataSetRef.getSimId() + "_" + simulationDataSetRef.getJobIndex() + "_.simref");
VisMeshUtils.writeSimulationDataSetRef(simDataSetRefFile, simulationDataSetRef);
envVarList.add("INITIALSIMDATAREFFILE=" + simDataSetRefFile.getPath().replace("\\", "/"));
}
// @SuppressWarnings("unused")
new Thread(new Runnable() {
@Override
public void run() {
try {
Executable exec = new Executable(cmdStringArray);
// Executable exec = new Executable(new String[] {st});
for (String var : envVarList) {
StringTokenizer st2 = new StringTokenizer(var, "=");
exec.addEnvironmentVariable(st2.nextToken(), st2.nextToken());
}
exec.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
if (lg.isInfoEnabled()) {
lg.info("Started VCellVisIt");
}
/*
List<String> cmds = new ArrayList<String>();
cmds.add(visitExecutable.getAbsolutePath());
cmds.add("-cli");
cmds.add("-ufile");
cmds.add(script.getAbsolutePath());
ProcessBuilder pb = new ProcessBuilder(cmds);
final Process p = pb.start();
Runnable mon = new Runnable() {
@Override
public void run() {
try {
System.err.println("waiting for visit");
p.waitFor();
int rcode = p.exitValue();
System.err.println("visit exit code " + rcode);
} catch (Exception e) {
e.printStackTrace();
}
}
};
new Thread(mon).start();
*/
}
use of org.vcell.util.exe.Executable in project vcell by virtualcell.
the class NagiosVCellMonitor method getPidOnPortLinuxLocal.
public static Integer getPidOnPortLinuxLocal(int port) throws Exception {
// lsof -iTCP -sTCP:LISTEN -P -n
Executable executable = new Executable(createLSOFPort_LinuxCmdParams(port));
try {
executable.start();
} catch (Exception e) {
// this can happen is there are no processes we have permission to list
// assume the other monitor isn't running
e.printStackTrace();
return null;
}
String s = executable.getStdoutString();
return parseLSOF_ReturnPID(s, port);
}
Aggregations