TranslateTool.RunProgram.Run C# (CSharp) Method

Run() public method

public Run ( string exeName, string commandLine, string directory ) : int
exeName string
commandLine string
directory string
return int
        public int Run(string exeName, string commandLine, string directory)
        {
            ProcessStartInfo startInfo = new ProcessStartInfo(exeName, commandLine);
            startInfo.RedirectStandardError = true;
            startInfo.RedirectStandardOutput = true;
            startInfo.UseShellExecute = false;
            startInfo.WindowStyle = ProcessWindowStyle.Normal;
            startInfo.WorkingDirectory = directory;
            startInfo.CreateNoWindow = true;
            startInfo.ErrorDialog = true;

            Process process = Process.Start(startInfo);
            process.OutputDataReceived += new DataReceivedEventHandler(DataReceived);
            process.ErrorDataReceived += new DataReceivedEventHandler(DataReceived);
            process.BeginErrorReadLine();
            process.BeginOutputReadLine();

            process.WaitForExit();

            int exitCode = process.ExitCode;
            process.Close();
            return exitCode;
        }

Usage Example

Exemplo n.º 1
0
        private void dialogEditorButton_Click(object sender, EventArgs e)
        {
            if (listViewStrings.SelectedItems.Count > 0)
            {
                ListViewItem item = listViewStrings.SelectedItems[0];
                LocString    str  = (LocString)item.Tag;

                Save();

                string winResExe = RunProgram.FindSDKTool("winres.exe");
                if (winResExe == null)
                {
                    MessageBox.Show(@"Cannot find al.exe in the Windows SDK. Make sure the Windows SDK is installed in c:\Program Files\Microsoft SDKs\Windows");
                }
                else
                {
                    // The unlocalized file must be copied to the same directory as the localized for winres to work.
                    string resXFileName          = str.File.LocalizedFileName;
                    string resXUnlocalized       = str.File.NonLocalizedFileName;
                    string resXCopiedUnlocalized = Path.Combine(Path.GetDirectoryName(resXFileName), Path.GetFileName(resXUnlocalized));
                    bool   copy = !string.Equals(resXUnlocalized, resXCopiedUnlocalized, StringComparison.InvariantCultureIgnoreCase);

                    if (copy)
                    {
                        File.Copy(resXUnlocalized, resXCopiedUnlocalized, true);
                    }

                    Enabled = false;
                    try {
                        RunProgram runProgram = new RunProgram();
                        runProgram.Run(winResExe, Path.GetFileName(resXFileName), Path.GetDirectoryName(resXFileName));
                    }
                    finally {
                        Enabled = true;
                        Activate();
                    }

                    if (copy)
                    {
                        File.Delete(resXCopiedUnlocalized);
                    }

                    resourceDirectory.ReadResources();
                    PopulateListView();
                }
            }
        }
All Usage Examples Of TranslateTool.RunProgram::Run