本文整理汇总了C#中System.Diagnostics.Process.Query方法的典型用法代码示例。如果您正苦于以下问题:C# Process.Query方法的具体用法?C# Process.Query怎么用?C# Process.Query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.Process
的用法示例。
在下文中一共展示了Process.Query方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public List<TestRunResults> Run(string arguments, string workingDirectory, string testLocation, Action<string> onLine) {
var file = Path.GetTempFileName();
if (File.Exists(file))
File.Delete(file);
var results = new List<TestRunResults>();
var errors = new StringBuilder();
var lastStatus = DateTime.Now;
var proc = new Process();
var procArguments = "--log-junit \"" + file + "\" --tap " + arguments;
AutoTest.Core.DebugLog.Debug.WriteDebug("Running: phpunit " + procArguments);
proc.Query(
"phpunit",
procArguments,
false,
workingDirectory,
(error, line) => {
if (error) {
errors.AppendLine(line);
proc.Kill();
return;
}
if (DateTime.Now.Subtract(lastStatus) > TimeSpan.FromMilliseconds(300)) {
onLine(line);
lastStatus = DateTime.Now;
}
});
if (errors.Length != 0) {
AutoTest.Core.DebugLog.Debug.WriteDebug("Parse error is: " + errors);
results
.Add(
new TestRunResults(
"PHP Parse error",
testLocation,
true,
TestRunner.PhpParseError,
new[] {
PhpUnitParseErrorParser.Parse(errors.ToString())
}));
} else {
results.Add(removeParseErrorsForLocation(testLocation));
}
AutoTest.Core.DebugLog.Debug.WriteDebug("Error length is " + errors.Length + " and file exists for file " + file + " is " + File.Exists(file).ToString());
if (errors.Length == 0 && File.Exists(file)) {
AutoTest.Core.DebugLog.Debug.WriteDebug("Prasing output for " + file);
var testRunResults = JUnitXmlParser.Parse(File.ReadAllText(file), testLocation);
var finalResults = removeDeletedTests(testRunResults);
results.AddRange(finalResults);
}
return results;
}
示例2: execute
private void execute(Process proc, string cmd, string arguments, Action<bool, string> onLineReceived)
{
Logger.Write("Executing {0} {1}", cmd, arguments);
if (onLineReceived != null)
proc.Query(cmd, arguments, false, Environment.CurrentDirectory, onLineReceived);
else
proc.Run(cmd, arguments, false, Environment.CurrentDirectory);
}
示例3: run
private void run(string arguments)
{
var proc = new Process();
proc.Query(
"oi",
arguments,
false,
_directory,
(error, line) => {
if (error) {
Logger.Write("Failed to run oi with " + arguments + " in " + _directory);
Logger.Write(line);
return;
}
Console.WriteLine(line);
});
/*if (Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX)
proc.StartInfo = new ProcessStartInfo("oi", arguments);
else
{
proc.StartInfo =
new ProcessStartInfo(
"cmd.exe", "/c oi \"" +
arguments.Replace("\"", "^\"") + "\"");
}
Console.WriteLine("Running: " + proc.StartInfo.FileName + " " + proc.StartInfo.Arguments);
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.WorkingDirectory = _directory;
proc.Start();
var output = proc.StandardOutput.ReadToEnd();
if (output.Length > Environment.NewLine.Length)
output = output.Substring(0, output.Length - Environment.NewLine.Length);
Console.WriteLine(output);*/
}
示例4: Execute
public void Execute(string[] arguments)
{
if (arguments.Length < 1)
return;
var scriptName = arguments[0];
var script =
Bootstrapper.GetDefinitionBuilder()
.Definitions
.FirstOrDefault(x => x.Name == scriptName &&
(x.Type == DefinitionCacheItemType.Script ||
x.Type == DefinitionCacheItemType.LanguageScript));
if (script == null)
return;
var root = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var match1 = "codemodel raw-filesystem-change-filecreated \"" + script.Location + "\"";
var match2 = "codemodel raw-filesystem-change-filechanged \"" + script.Location + "\"";
Logger.Write("Looking for: " + match1);
Logger.Write("Looking for: " + match2);
var hash = 0;
try {
var proc = new Process();
proc.Query(
Path.Combine(root, Path.Combine("EventListener", "OpenIDE.EventListener.exe")),
"",
false,
_token,
(error, s) => {
if (s == match1 || s == match2) {
var newHas = File.ReadAllText(script.Location).GetHashCode();
if (newHas != hash) {
hash = newHas;
_dispatch("Running command:");
runCommand(arguments);
}
}
}
);
} catch (Exception ex) {
Logger.Write(ex);
}
}
示例5: query
private void query(string cmd, string arguments, string filter, Action<string> onMatch)
{
if (filter != null) {
_matcher = new Regex(
"^" + Regex.Escape(filter)
.Replace( "\\*", ".*" )
.Replace( "\\?", "." ) + "$");
}
try {
var proc = new Process();
proc.Query(
cmd,
arguments,
false,
_path,
(error, s) => {
if (error || filter == null || match(s))
onMatch(s);
});
} catch (Exception ex) {
Console.WriteLine(ex.ToString());
}
}
示例6: Execute
public void Execute(string[] arguments)
{
if (arguments.Length < 2)
return;
var scripts = new ReactiveScriptReader(
_token,
_pluginLocator,
(p, m) => {},
(m) => {})
.Read();
var script = scripts.FirstOrDefault(x => x.Name.Equals(arguments[0]));
if (script == null)
return;
var root = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var match1 = "'codemodel' 'raw-filesystem-change-filecreated' '" + script.File + "'";
var match2 = "'codemodel' 'raw-filesystem-change-filechanged' '" + script.File + "'";
Logger.Write("Looking for: " + match1);
Logger.Write("Looking for: " + match2);
var name = "rscript-" + Path.GetFileNameWithoutExtension(script.File);
var hash = 0;
try {
using (var output = new OutputClient(_token, (publisher, msg) => { if (name == publisher) _dispatch(msg); }))
{
output.Connect();
var proc = new Process();
proc.Query(
Path.Combine(root, Path.Combine("EventListener", "OpenIDE.EventListener.exe")),
"",
false,
_token,
(error, s) => {
if (s == match1 || s == match2) {
var newHas = File.ReadAllText(script.File).GetHashCode();
if (newHas != hash) {
hash = newHas;
Thread.Sleep(200);
_dispatch("");
_dispatch("Triggering reactive script:");
_dispatch("event|"+arguments[1]);
}
}
}
);
}
} catch (Exception ex) {
Logger.Write(ex);
}
}
示例7: run
private string run(string arguments)
{
var proc = new Process();
var sb = new StringBuilder();
proc.Query(
_file,
arguments,
false,
Environment.CurrentDirectory,
(error, s) => {
if (error) {
sb.AppendLine("error|" + s);
return;
}
sb.AppendLine(s);
});
var output = sb.ToString();
if (output.Length > Environment.NewLine.Length)
return output.Substring(0, output.Length - Environment.NewLine.Length);
return output;
}
示例8: run
private void run(string arguments, Action<string> onLine,
IEnumerable<KeyValuePair<string,string>> replacements)
{
var cmd = _file;
var finalReplacements = new List<KeyValuePair<string,string>>();
finalReplacements.Add(new KeyValuePair<string,string>("{run-location}", "\"" + _workingDirectory + "\""));
finalReplacements.AddRange(replacements);
arguments = "{run-location} " + arguments;
var proc = new Process();
_writer = (msg) => {
try {
Logger.Write("Writing to the process " + msg);
proc.Write(msg);
} catch (Exception ex) {
Logger.Write(ex);
}
};
var realArguments = arguments;
proc
.Query(
cmd,
arguments,
false,
_token,
(error, line) => {
if (error && !line.StartsWith("error|")) {
onLine("error|" + line);
Logger.Write(line);
} else
onLine(line);
},
finalReplacements.ToArray(),
(args) => realArguments = args);
onLine(string.Format("event|builtin command ran \"{0}\" {1}", Name, realArguments));
_writer = (msg) => {};
}
示例9: Execute
public void Execute(string[] arguments)
{
_verbose = arguments.Contains("-v");
_showoutputs = arguments.Contains("-o");
_showevents = arguments.Contains("-e");
_printOnlyErrorsAndInconclusives = arguments.Contains("--only-errors");
_logging = arguments.Contains("-l");
var profiles = new ProfileLocator(_token);
var testFiles = new List<string>();
if (arguments.Length > 0 && File.Exists(arguments[0])) {
testFiles.Add(arguments[0]);
} else {
testFiles
.AddRange(
getTests(profiles.GetLocalProfilePath("default")));
testFiles
.AddRange(
getTests(profiles.GetGlobalProfilePath("default")));
testFiles
.AddRange(
getTests(
Path.GetDirectoryName(
Assembly.GetExecutingAssembly().Location)));
}
foreach (var testFile in testFiles) {
_testRunLocation = Path.Combine(Path.GetTempPath(), DateTime.Now.Ticks.ToString());
Console.WriteLine("Testing: {0}", testFile);
var eventListenerStarted = false;
var systemStarted = false;
var runCompleted = false;
var eventListener = new Thread(() => {
var eventSocketClient = new EventStuff.EventClient(
(line) => {
if (line == "codeengine started") {
log("Code engine started");
systemStarted = true;
} if (line == "codeengine stopped") {
log("Code engine stopped");
runCompleted = true;
}
_events.Add(line);
});
while (true) {
eventSocketClient.Connect(_testRunLocation);
eventListenerStarted = true;
if (!eventSocketClient.IsConnected) {
Thread.Sleep(10);
if (runCompleted || systemStarted)
break;
continue;
}
log("Event listener connected");
while (eventSocketClient.IsConnected)
Thread.Sleep(10);
break;
}
eventListenerStarted = false;
});
var isQuerying = false;
var useEditor = false;
var tests = new List<string>();
Process proc = null;
try {
Directory.CreateDirectory(_testRunLocation);
_events = new List<string>();
_outputs = new List<string>();
_asserts = new List<string>();
log("Initializing test location");
runCommand("init");
// Make sure we run tests in default profile is
// this by any chance overloaded in init command
runCommand("profile load default");
eventListener.Start();
new Thread(() => {
log("Starting test process");
var testProc = new Process();
try {
testProc
.Query(
testFile,
_testRunLocation,
false,
Environment.CurrentDirectory,
(error, line) => {
if (line == "initialized" || line.StartsWith("initialized|")) {
log("Test file initialized");
proc = testProc;
var chunks = line.Split(new[] {'|'});
if (chunks.Length > 1 && chunks[1] == "editor") {
while (!eventListenerStarted)
Thread.Sleep(10);
log("Starting editor");
new Process().Run("oi", "editor test", false, _testRunLocation);
log("Editor launched");
useEditor = true;
//.........这里部分代码省略.........
示例10: run
private void run(string arguments)
{
var proc = new Process();
proc.Query(
"oi",
arguments,
false,
_directory,
(error, line) => {
if (error) {
Logger.Write("Failed to run oi with " + arguments + " in " + _directory);
Logger.Write(line);
return;
}
Console.WriteLine(line);
});
}
示例11: startService
private void startService()
{
_service = new Process();
try
{
var responseDispatcher = new ResponseDispatcher(
_keyPath,
_dispatchErrors,
"rscript-" + Name + " ",
_outputDispatcher,
internalDispatch,
(response) => _service.Write(response)
);
_service.SetLogger((logMsg) => Logger.Write(logMsg));
_service.Query(
_file,
"{global-profile} {local-profile}",
false,
_keyPath,
(error, m) => {
if (m == null)
return;
Logger.Write("request doing " + m);
if (error) {
Logger.Write("rscript-" + Name + " produced an error:");
Logger.Write("rscript-" + Name + "-" + m);
}
responseDispatcher.Handle(error, m);
},
new[] {
new KeyValuePair<string,string>("{global-profile}", "\"" + _globalProfileName + "\""),
new KeyValuePair<string,string>("{local-profile}", "\"" + _localProfileName + "\"")
});
Logger.Write("Exiting service script");
}
catch (Exception ex)
{
internalDispatch("rscript-" + Name + " " + ex.ToString());
Logger.Write(ex.ToString());
}
}
示例12: runScript
private void runScript(string message)
{
if (_isFaulted)
return;
var originalMessage = message;
message = "{event} {global-profile} {local-profile}";
Logger.Write("Running: " + _file + " " + message);
ThreadPool.QueueUserWorkItem((task) => {
try
{
var process = new Process();
var responseDispatcher = new ResponseDispatcher(
_keyPath,
_dispatchErrors,
"rscript-" + Name + " ",
_outputDispatcher,
internalDispatch,
(response) => process.Write(response)
);
process.SetLogger((logMsg) => Logger.Write(logMsg));
var msg = task.ToString();
process.Query(
_file,
msg,
false,
_keyPath,
(error, m) => {
if (m == null)
return;
Logger.Write("request doing " + m);
if (error) {
Logger.Write("rscript-" + Name + " produced an error:");
Logger.Write("rscript-" + Name + "-" + m);
}
responseDispatcher.Handle(error, m);
},
new[] {
new KeyValuePair<string,string>("{event}", "\"" + originalMessage + "\""),
new KeyValuePair<string,string>("{global-profile}", "\"" + _globalProfileName + "\""),
new KeyValuePair<string,string>("{local-profile}", "\"" + _localProfileName + "\"")
});
Logger.Write("RScript completed");
}
catch (Exception ex)
{
internalDispatch("rscript-" + Name + " " + ex.ToString());
Logger.Write(ex.ToString());
}
}, message);
}
示例13: Run
public void Run(string message)
{
if (Environment.OSVersion.Platform != PlatformID.Unix &&
Environment.OSVersion.Platform != PlatformID.MacOSX)
{
message = message
.Replace(" ", "^ ")
.Replace("|", "^|")
.Replace("%", "^&")
.Replace("&", "^&")
.Replace("<", "^<")
.Replace(">", "^>");
}
var originalMessage = message;
message = "{event} {global-profile} {local-profile}";
Logger.Write("Running: " + _file + " " + message);
ThreadPool.QueueUserWorkItem((task) => {
try
{
var process = new Process();
process.SetLogger((logMsg) => Logger.Write(logMsg));
var msg = task.ToString();
process.Query(
_file,
msg,
false,
_keyPath,
(error, m) => {
if (m == null)
return;
var cmdText = "command|";
var eventText = "event|";
if (error) {
Logger.Write("rscript-" + Name + " produced an error:");
Logger.Write("rscript-" + Name + "-" + m);
} else {
if (m.StartsWith(cmdText))
_dispatch(m.Substring(cmdText.Length, m.Length - cmdText.Length));
else if (m.StartsWith(eventText))
_dispatch(m.Substring(eventText.Length, m.Length - eventText.Length));
else
_dispatch("rscript-" + Name + " " + m);
}
},
new[] {
new KeyValuePair<string,string>("{event}", "\"" + originalMessage + "\""),
new KeyValuePair<string,string>("{global-profile}", "\"" + _globalProfileName + "\""),
new KeyValuePair<string,string>("{local-profile}", "\"" + _localProfileName + "\"")
});
}
catch (Exception ex)
{
Logger.Write(ex.ToString());
}
}, message);
}
示例14: run
private string run(string arguments)
{
var proc = new Process();
var sb = new StringBuilder();
foreach (var line in proc.Query(_file, arguments, false, Environment.CurrentDirectory))
sb.AppendLine(line);
var output = sb.ToString();
if (output.Length > Environment.NewLine.Length)
return output.Substring(0, output.Length - Environment.NewLine.Length);
return output;
}