def app_launch(executable, teardown=None, params='', _assert=False, **kw): """ App Launch | <executable> [ | params | <cmdline parameters string> ] [ | flags and params ] Launches an app. The first parameter is a path to the app's executable. Optional 'suite_teardown' or 'test_teardown' flags force to kill the app at the end of the suite or of the test, respectively (if still running). A 'params' named parameter is also optional, should be followed by a parameters string (all args in one). :return: An application object or None in case of failure if "assert" flag is not present. """ pi = ProcessStartInfo(executable, params) workdir = kw.get('workdir', '') if workdir!='': pi.WorkingDirectory=workdir logging.info(workdir) try: app = Application.Launch(pi) except: if _assert: logging.error('Failed to launch an executable') raise logging.warning('Failed to launch an executable') return None if teardown == 'test': CONTROLLED_APPS[-1].append(app) elif teardown == 'suite': SUITE_CONTROLLED_APPS[-2].append(app) return app
def StartRevitProcess(revitVersion, initEnvironmentVariables): revitExecutableFilePath = RevitVersion.GetRevitExecutableFilePath(revitVersion) psi = ProcessStartInfo(revitExecutableFilePath) psi.UseShellExecute = False psi.RedirectStandardError = True psi.RedirectStandardOutput = True psi.WorkingDirectory = RevitVersion.GetRevitExecutableFolderPath(revitVersion) initEnvironmentVariables(psi.EnvironmentVariables) revitProcess = Process.Start(psi) return revitProcess
def StartCmdProcess(commandLine, workingDirectory=None): # NOTE: do not call Process.WaitForExit() until redirected streams have been entirely read from / closed. # doing so can lead to a deadlock when the child process is waiting on being able to write to output / error # stream and the parent process is waiting for the child to exit! See Microsoft's documentation for more info. # NOTE: if redirecting both output and error streams, one should be read asynchronously to avoid a deadlock where # the child process is waiting to write to one of the streams and the parent is waiting for data from the other # stream. See Microsoft's documentation for more info. psi = ProcessStartInfo('cmd.exe', '/S /C " ' + commandLine + ' "') psi.UseShellExecute = False psi.CreateNoWindow = True # TODO: does this need to be set? what should it be? what will it be by default? if workingDirectory is not None: psi.WorkingDirectory = workingDirectory psi.RedirectStandardInput = False psi.RedirectStandardError = True # See notes above if enabling this alongside redirect output stream. psi.RedirectStandardOutput = True process = Process.Start(psi) return process
def RunICM(Adapter): """ <Script> <Author>ANK</Author> <Description>run an ICM model</Description> <Parameters> <Parameter name="Adapter" type="IRuntimeAdapter">handle to the adapter</Parameter> </Parameters> </Script> """ tsMgr = app.Modules.Get("Time series Manager") # get the adapter root folder rootfolder = Adapter.RootFolderPath # convert dfs0-input files to Dummy_Inflow.csv # open dummy inflow and read all lines inflowPath = Path.Combine(rootfolder, "MODEL_SETUP\\import\\Dummy Inflow.csv") inflowLines = File.ReadAllLines(inflowPath) # read dfs0-files one by one l=8 tslist = [] while inflowLines[l].split(",")[0]!="P_DATETIME" : tsname = inflowLines[l].split(",")[0] tsFile = Path.Combine(rootfolder, "INPUT_DATA", tsname+".dfs0") tslist.extend(TsUtilities.ReadFromDFS0(tsMgr, tsFile)) l = l + 1; # make new lines newLines = [] i=0 while True: if i==6: # replace startdate line = tslist[0].Start.ToString("dd/MM/yyyy HH:mm:ss") + inflowLines[i][19:] else: line = inflowLines[i] newLines.append(line) if inflowLines[i].split(",")[0]=="P_DATETIME" : break; i = i + 1; # continue with timesteps for t in range(tslist[0].Count): line = tslist[0].Get(t).XValue.ToString("dd/MM/yyyy HH:mm:ss") for ds in tslist: line += "," + ds.Get(t).YValue.ToString(CultureInfo.InvariantCulture) newLines.append(line) # rewrite the input file File.WriteAllLines(inflowPath, newLines) # run the adapter bat-file startInfo = ProcessStartInfo() startInfo.CreateNoWindow = False; startInfo.UseShellExecute = False; startInfo.FileName = Path.Combine(rootfolder, "MODEL_SETUP", "run.bat"); startInfo.WorkingDirectory = Path.Combine(rootfolder, "MODEL_SETUP") with Process.Start(startInfo) as exeProcess : exeProcess.WaitForExit(); # convert exported csv-files to dfs0 # convert node depths dslist = [] for fil in Directory.GetFiles(Path.Combine(rootfolder,"MODEL_SETUP\\export"),"Node_*_depnod.csv"): lines = File.ReadAllLines(fil) headers = lines[0].split(",") for h in headers[2:]: ds = tsMgr.TimeSeriesList.CreateNew() ds.Name = h.strip() ds.YAxisVariable = "Water Level" dslist.append(ds) for line in lines[1:] : if not "[" in line: values = line.split(",") t = DateTime.ParseExact(values[0].strip(),"dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture) for v in range(2,values.Count): ds = dslist[v-2] vp = ds.CreateNew() vp.XValue = t vp.YValue = Double.Parse(values[v].strip(), CultureInfo.InvariantCulture) ds.Add(vp) # save to dfs0 for ds in dslist: fil = Path.Combine(rootfolder,"OUTPUT_DATA",ds.Name+".dfs0") TsUtilities.ExportToDfs0(ds,fil)
# <command> # <description>Startet ein externes Programm</description> # <param name="program" type="file">Pfad zum Programm</param> # <param name="arguments" type="string">(optional) Parameter für das Programm</param> # <param name="directorz" type="dir">(optional) Verzeichnis in dem das Programm ausgeführt wird</param> # </command> from System.Diagnostics import Process, ProcessStartInfo setup = ProcessStartInfo(program, arguments) if directory is not None: setup.WorkingDirectory = directory Process.Start(setup)
import clr clr.AddReference('System') from System.Diagnostics import Process, ProcessStartInfo processes = Process.GetProcessesByName('Dropbox') if len(processes) == 0: processStartInfo = ProcessStartInfo() processStartInfo.WorkingDirectory = r"C:\Users\Andrius\AppData\Roaming\Dropbox\bin" processStartInfo.FileName = 'Dropbox.exe' dropbox = Process.Start(processStartInfo)