///////////////////////////////////////////////////////////////////////////// public static ExecResult RunNode( string pathToNode, string cmdLine, int waitTime ) { // ****** if( string.IsNullOrEmpty( pathToNode ) ) { pathToNode = FindExe( "node.exe" ); } // ****** var external = new External(); return external.Execute( pathToNode, false, cmdLine, waitTime ); }
///////////////////////////////////////////////////////////////////////////// public bool Run( ERCommand erCmd, out string result ) { // ****** result = null; if( Debugger.IsAttached && erCmd.DebugBreak ) { Debugger.Break(); } // ****** var execuitable = erCmd.ExecutableName; if( string.IsNullOrWhiteSpace( execuitable ) ) { service.NotifyOfErrors( ErrorType.PrepError, "no command name was provided" ); return false; } // ****** const string INTERNAL = "internal:"; if( execuitable.StartsWith( INTERNAL, StringComparison.OrdinalIgnoreCase ) ) { return TryHandleInternalCmd( execuitable.Substring( INTERNAL.Length ), erCmd, input, out result ); } // ****** var cmdExt = Path.GetExtension( execuitable ); // // should look this up in the registery // if( ".cmd" == cmdExt || ".bat" == cmdExt ) { execuitable = "cmd.exe"; } else if( ".btm" == cmdExt ) { execuitable = "tcc.exe"; } // ****** bool success = false; var bareFileName = input.NameWithoutExt; var cmdInputFile = GetTempFilePath( bareFileName ); var cmdOutputFile = GetFilePath( bareFileName, ".out.txt" ); try { var proccessedInputText = ProcessOptions( input.Content ); var commandLine = erCmd.SubstituteAndCombine( input, cmdInputFile, cmdOutputFile, new List<string> { } ); // ****** WriteNmpInputFile( cmdInputFile, proccessedInputText ); // ****** var run = new External { }; var exeResult = run.Execute( execuitable, false, commandLine, 10000 ); if( exeResult.Success ) { var exitCode = exeResult.ExitCode; if( ActionEnum.RunOnlyIgnoreExitCode == erCmd.ActionEnum ) { // // don't expect or handle output file, no exit code check // success = true; } else if( ActionEnum.RunOnly == erCmd.ActionEnum ) { // // don't expect or handle output file, do check exit code // success = 0 == exitCode; } else { // // expect output, do check exit code // if( 0 == exitCode ) { // // success // success = true; if( erCmd.ReadStdout ) { result = exeResult.StdOut; } else if( File.Exists( cmdOutputFile ) ) { result = ReadNmpOutputFile( cmdOutputFile ); } else { result = null; } //if( success ) { service.NotifyOfSuccess(); //} } else { // // failure // //var errStr = FixSrcNameInStdErr( exeResult.StdErr, cmdInputFile, input.NameWithPath ); var errStr = exeResult.StdErr.Replace( cmdInputFile, input.NameWithPath ); service.NotifyOfErrors( ErrorType.Error, errStr ); success = false; } } } else { // // failed to execute cmd // service.NotifyOfErrors( ErrorType.FailureToExecute, execuitable ); success = false; } } finally { if( !KeepTempFiles ) { ResultFilesHelper.DeleteFiles( new List<string> { cmdInputFile, cmdOutputFile } ); } } // ****** return success; }