本文整理汇总了C#中ProcessStartInfo类的典型用法代码示例。如果您正苦于以下问题:C# ProcessStartInfo类的具体用法?C# ProcessStartInfo怎么用?C# ProcessStartInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProcessStartInfo类属于命名空间,在下文中一共展示了ProcessStartInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public static bool Execute(ProjectProperties properties, Log log)
{
Console.WriteLine("compiling");
var processSettings = new ProcessStartInfo();
processSettings.FileName = properties.CscPath;
processSettings.Arguments = properties.FormatCscArguments();
log.WriteLine("Executing {0}", processSettings.FileName);
log.WriteLine("Csc Arguments: {0}", processSettings.Arguments);
processSettings.CreateNoWindow = true;
processSettings.RedirectStandardOutput = true;
processSettings.UseShellExecute = false;
Process cscProcess = null;
try
{
cscProcess = Process.Start(processSettings);
}
catch (Win32Exception)
{
Console.WriteLine("ERROR: csc.exe needs to be on the path.");
return false;
}
var output = cscProcess.StandardOutput.ReadToEnd();
log.WriteLine(output);
cscProcess.WaitForExit();
if (output.Contains("error CS")) return false;
return true;
}
示例2: Execute
public static int Execute(string fileName, string arguments,
out string output)
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.UseShellExecute = false;
psi.RedirectStandardError = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.CreateNoWindow = true;
psi.ErrorDialog = false;
psi.FileName = fileName;
psi.Arguments = arguments;
using (Process process = Process.Start(psi))
{
process.StandardInput.Close();
StreamReader sOut = process.StandardOutput;
StreamReader sErr = process.StandardError;
output = sOut.ReadToEnd() + sErr.ReadToEnd();
sOut.Close();
sErr.Close();
process.WaitForExit();
return process.ExitCode;
}
}
示例3: ExecuteCommand
static void ExecuteCommand(string command)
{
int exitCode;
ProcessStartInfo processInfo;
Process process;
processInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
// *** Redirect the output ***
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;
process = Process.Start(processInfo);
process.WaitForExit();
// *** Read the streams ***
// Warning: This approach can lead to deadlocks, see Edit #2
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
exitCode = process.ExitCode;
Console.WriteLine("output>>" + (String.IsNullOrEmpty(output) ? "(none)" : output));
Console.WriteLine("error>>" + (String.IsNullOrEmpty(error) ? "(none)" : error));
Console.WriteLine("ExitCode: " + exitCode.ToString(), "ExecuteCommand");
process.Close();
}
示例4: RunPlistBuddyCommand
public static void RunPlistBuddyCommand(string workingDirectory, string arguments)
{
ProcessStartInfo proc = new ProcessStartInfo ("/usr/libexec/PlistBuddy", "Info.plist -c \"" + arguments + "\"");
proc.WorkingDirectory = workingDirectory;
proc.UseShellExecute = false;
Process.Start(proc);
}
示例5: Main
static void Main()
{
for (;;)
{
var start = DateTime.Now;
var info = new ProcessStartInfo("xbuild") {
RedirectStandardError = true,
UseShellExecute = false,
RedirectStandardOutput = true,
};
var proc = Process.Start(info);
proc.WaitForExit();
if (proc.ExitCode != 0) {
var allerrs = proc.StandardError
.ReadToEnd().Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
.Concat(
proc.StandardOutput.ReadToEnd().Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
)
.Where(line => line.Contains("error"))
.ToList();
Process.Start("osascript", string.Format("-e 'display notification \"{0}\" with title \"Home CI\"'",
string.Join(" / ", allerrs.Select(line => line.Replace("\"", "\\\"").Replace("'", "`")))));
}
var wait = min_seconds - (int)(DateTime.Now - start).TotalSeconds;
if (wait > 0)
System.Threading.Thread.Sleep(wait * 1000);
}
}
示例6: Run
public static void Run(string name)
{
if (name.EndsWith("/")) name = name.Substring(0,name.Length-1);
#if UNITY_STANDALONE_OSX || UNITY_EDITOR // Cut "|| UNITY_EDITOR" if you're using windows
if (name.EndsWith(".app"))
{
name = name + "/Contents/MacOS/";
string[] nn = Directory.GetFiles(name);
name = nn[0];
}
ProcessStartInfo startInfo = new ProcessStartInfo( name);
startInfo.UseShellExecute = false;
startInfo.WorkingDirectory = CurrentDir();
Process.Start(startInfo);
#elif UNITY_STANDALONE_WIN // Paste "|| UNITY_EDITOR" if you're using windows
ProcessStartInfo startInfo = new ProcessStartInfo( name);
startInfo.UseShellExecute = true;
startInfo.WorkingDirectory = CurrentDir();
Process.Start(startInfo);
#else
Debug.LogError("Sorry, I can't open a file on this platform");
#endif
GUIUtility.ExitGUI();
}
示例7: LaunchEmulator
static void LaunchEmulator ()
{
ProcessStartInfo startInfo = new ProcessStartInfo ()
{
WorkingDirectory = Application.dataPath,
FileName = JavaBuildSettings.AndroidSDKPath + "/../../tools/emulator",
Arguments = string.Format (
"-avd {0}",
"OUYA"
),
UseShellExecute = false,
RedirectStandardError = true,
};
Process process = Process.Start (startInfo);
process.Exited += new EventHandler (
(object sender, EventArgs e) =>
{
if (!process.StandardError.EndOfStream)
{
Debug.LogError (
"Android emulator error: " +
process.StandardError.ReadToEnd ()
);
}
}
);
}
示例8: Main
public static int Main(string[] args)
{
ProcessStartInfo startInfo = new ProcessStartInfo("[EXE]", "[ARGUMENTS] " + GetArguments(args));
startInfo.UseShellExecute = false;
Process process;
try
{
try
{
process = Process.Start(startInfo);
}
catch (Win32Exception ex)
{
if (ex.NativeErrorCode == Win32RequestedOperationRequiresElevation)
{
// UAC handling requires ShellExecute
startInfo.UseShellExecute = true;
process = Process.Start(startInfo);
}
else throw;
}
process.WaitForExit();
}
catch (Win32Exception ex)
{
if (ex.NativeErrorCode == Win32Cancelled) return 100;
else throw;
}
return process.ExitCode;
}
示例9: GetMXServers
public IList<MXServer> GetMXServers(string domainName)
{
string command = "nslookup -q=mx " + domainName;
ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd", "/c " + command);
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
Process proc = new Process();
proc.StartInfo = procStartInfo;
proc.Start();
string result = proc.StandardOutput.ReadToEnd();
if (!string.IsNullOrEmpty(result))
result = result.Replace("\r\n", Environment.NewLine);
IList<MXServer> list = new List<MXServer>();
foreach (string line in result.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
{
if (line.Contains("MX preference =") && line.Contains("mail exchanger ="))
{
MXServer mxServer = new MXServer();
mxServer.Preference = Int(GetStringBetween(line, "MX preference = ", ","));
mxServer.MailExchanger = GetStringFrom(line, "mail exchanger = ");
list.Add(mxServer);
}
}
return list.OrderBy(m => m.Preference).ToList();
}
示例10: CallProcess
static bool CallProcess(string processName, string param)
{
ProcessStartInfo process = new ProcessStartInfo
{
CreateNoWindow = false,
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardOutput = true,
FileName = processName,
Arguments = param,
};
UnityEngine.Debug.Log(processName + " " + param);
Process p = Process.Start(process);
p.StandardOutput.ReadToEnd();
p.WaitForExit();
string error = p.StandardError.ReadToEnd();
if (!string.IsNullOrEmpty(error))
{
UnityEngine.Debug.LogError(processName + " " + param + " ERROR! " + "\n" + error);
string output = p.StandardOutput.ReadToEnd();
if (!string.IsNullOrEmpty(output))
{
UnityEngine.Debug.Log(output);
}
return false;
}
return true;
}
示例11: Main
static int Main (string [] args)
{
string runtimeEngine = null;
if (args.Length == 0)
return 1;
if (args.Length > 1 && args [1].Length > 0)
runtimeEngine = args [1];
if (args [0] == "nested")
return 0;
string program = Path.Combine (AppDomain.CurrentDomain.BaseDirectory,
"test.exe");
ProcessStartInfo pinfo = null;
if (runtimeEngine != null) {
pinfo = new ProcessStartInfo (runtimeEngine, "\"" + program + "\" nested");
} else {
pinfo = new ProcessStartInfo (program, "nested");
}
pinfo.UseShellExecute = false;
pinfo.RedirectStandardInput = true;
pinfo.RedirectStandardOutput = true;
Process p = Process.Start (pinfo);
if (p.StandardOutput.CurrentEncoding.BodyName != Console.OutputEncoding.BodyName) {
return 2;
}
if (p.StandardInput.Encoding.BodyName != Console.InputEncoding.BodyName)
return 3;
return 0;
}
示例12: GetCustomerMac
//这里是关键函数了
public string GetCustomerMac(string IP)
{
string dirResults = "";
ProcessStartInfo psi = new ProcessStartInfo();
Process proc = new Process();
psi.FileName = "nbtstat";
psi.RedirectStandardInput = false;
psi.RedirectStandardOutput = true;
psi.Arguments = "-a " + IP;
psi.UseShellExecute = false;
proc = Process.Start(psi);
dirResults = proc.StandardOutput.ReadToEnd();
proc.WaitForExit();
//匹配mac地址
Match m = Regex.Match(dirResults, "\\w+\\-\\w+\\-\\w+\\-\\w+\\-\\w+\\-\\w\\w");
//若匹配成功则返回mac,否则返回找不到主机信息
if (m.ToString() != "")
{
return m.ToString();
}
else
{
return "找不到主机信息";
}
}
示例13: GetPrefKeysMac
private void GetPrefKeysMac()
{
string homePath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string pListPath = homePath +"/Library/Preferences/unity." + PlayerSettings.companyName + "." +
PlayerSettings.productName + ".plist";
// Convert from binary plist to xml.
Process p = new Process();
ProcessStartInfo psi = new ProcessStartInfo("plutil", "-convert xml1 \"" + pListPath + "\"");
p.StartInfo = psi;
p.Start();
p.WaitForExit();
StreamReader sr = new StreamReader(pListPath);
string pListData = sr.ReadToEnd();
XmlDocument xml = new XmlDocument();
xml.LoadXml(pListData);
XmlElement plist = xml["plist"];
if (plist == null) return;
XmlNode node = plist["dict"].FirstChild;
while (node != null) {
string name = node.InnerText;
node = node.NextSibling;
PlayerPrefStore pref = new PlayerPrefStore(name, node.Name, node.InnerText);
node = node.NextSibling;
playerPrefs.Add(pref);
}
// // Convert plist back to binary
Process.Start("plutil", " -convert binary1 \"" + pListPath + "\"");
}
示例14: CaptureScreen
private IEnumerator CaptureScreen(string path)
{
// Wait till the last possible moment before screen rendering to hide the UI
yield return null;
GameObject.Find("ScreenShotCanvas").GetComponent<Canvas>().enabled = false;
path = "\"" + path + "\"";
ProcessStartInfo startInfo = new ProcessStartInfo()
{
FileName = "screencapture",
Arguments = path,
};
Process proc = new Process()
{
StartInfo = startInfo,
};
// Wait for screen rendering to complete
yield return new WaitForEndOfFrame ();
proc.Start();
// wait for the process to end
yield return new WaitForEndOfFrame ();
yield return new WaitForEndOfFrame ();
hasNewScreenShot = true;
GameObject.Find("ScreenShotCanvas").GetComponent<Canvas>().enabled = true;
}
示例15: LaunchAdapter
private static Process LaunchAdapter(int adaptee, int adapted)
{
var temp = Path.GetTempFileName() + ".ensimea.exe";
File.Copy(@"%SCRIPTS_HOME%\ensimea.exe".Expand(), temp);
var psi = new ProcessStartInfo();
psi.FileName = temp;
psi.Arguments = String.Format("{0} {1}", adaptee, adapted);
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
var p = new Process();
p.StartInfo = psi;
p.OutputDataReceived += (sender, args) => { if (args.Data != null) Console.WriteLine(args.Data); };
p.ErrorDataReceived += (sender, args) => { if (args.Data != null) Console.WriteLine(args.Data); };
if (p.Start()) {
p.BeginOutputReadLine();
p.BeginErrorReadLine();
return p;
} else {
return null;
}
}