public override IAsyncExecutionResult startExecutableAsync(string toExecute, string args, string workingDir = null) { string tempDir = String.Format("C:\\users\\{0}\\", _spec.kernelVMUsername); if (workingDir == null) { workingDir = tempDir; } execFileSet fileSet = prepareForExecution(toExecute, args, tempDir); NamePasswordAuthentication auth = new NamePasswordAuthentication { Username = _spec.kernelVMUsername, Password = _spec.kernelVMPassword, InteractiveSession = true }; VimClientImpl _vClient = conn.getConnection(); VirtualMachine _underlyingVM = conn.getMachine(); GuestOperationsManager gom = (GuestOperationsManager)_vClient.GetView(_vClient.ServiceContent.GuestOperationsManager, null); GuestAuthManager guestAuthManager = (GuestAuthManager)_vClient.GetView(gom.AuthManager, null); guestAuthManager.ValidateCredentialsInGuest(_underlyingVM.MoRef, auth); GuestProcessManager guestProcessManager = _vClient.GetView(gom.ProcessManager, null) as GuestProcessManager; GuestProgramSpec progSpec = new GuestProgramSpec { ProgramPath = fileSet.launcherPath, Arguments = "", WorkingDirectory = workingDir }; guestProcessManager.StartProgramInGuest(_underlyingVM.MoRef, auth, progSpec); return(new asyncExecutionResultViaFile(this, fileSet)); }
public int RunProcess( string executable, string args, bool waitForExit = false ) { GuestProcessManager processManager = new GuestProcessManager( _virtualHost, _manager.ProcessManager ); GuestProgramSpec arguments = new GuestProgramSpec { Arguments = args, ProgramPath = executable, WorkingDirectory = Path.GetDirectoryName( executable ) }; long pid = processManager.StartProgramInGuest( _vm.MoRef, _authentication, arguments ); int exitCode = 0; if ( waitForExit ) { while ( true ) { GuestProcessInfo process = processManager.ListProcessesInGuest( _vm.MoRef, _authentication, new[] {pid} ) .FirstOrDefault( p => p.Pid == pid ); if ( process == null || process.EndTime != null ) { if ( process != null && process.ExitCode.HasValue ) { exitCode = process.ExitCode.Value; } break; } Thread.Sleep( 60000 ); processManager.UpdateViewData(); } } return exitCode; }
public int StartProcessAndWaitForExit( string processLocationInVm, string arguments ) { GuestProcessManager processManager = new GuestProcessManager( _virtualMachine.Client, _manager.ProcessManager ); GuestProgramSpec args = new GuestProgramSpec { Arguments = arguments, ProgramPath = processLocationInVm, WorkingDirectory = Path.GetDirectoryName( processLocationInVm ) }; long pid = processManager.StartProgramInGuest( _virtualMachine.MoRef, _authentication, args ); int exitCode = 0; while ( true ) { GuestProcessInfo process = processManager.ListProcessesInGuest( _virtualMachine.MoRef, _authentication, new[] {pid} ) .FirstOrDefault( p => p.Pid == pid ); if ( process == null || process.EndTime != null ) { if ( process != null && process.ExitCode.HasValue ) { exitCode = process.ExitCode.Value; } break; } Thread.Sleep( 6000 ); processManager.UpdateViewData(); } return exitCode; }
public void StartProcess( string processLocationInVm, string arguments ) { GuestProcessManager processManager = new GuestProcessManager( _virtualMachine.Client, _manager.ProcessManager ); GuestProgramSpec args = new GuestProgramSpec { Arguments = arguments, ProgramPath = processLocationInVm, WorkingDirectory = Path.GetDirectoryName( processLocationInVm ) }; processManager.StartProgramInGuest( _virtualMachine.MoRef, _authentication, args ); }