本文整理汇总了C#中System.Diagnostics.Process.Write方法的典型用法代码示例。如果您正苦于以下问题:C# Process.Write方法的具体用法?C# Process.Write怎么用?C# Process.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.Process
的用法示例。
在下文中一共展示了Process.Write方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public void Run(string arguments, Action<string> onLine)
{
var process = new Process();
_isRunning = true;
var stdinForwarder = new Thread(() => {
try {
while (_isRunning) {
var line = Console.ReadLine();
process.Write(line);
}
} catch {
}
});
stdinForwarder.Start();
Logger.Write("Running script {0} with {1}", _file, arguments);
arguments = "{global-profile} {local-profile} " + arguments;
run(
arguments,
(m) => {
var requestRunner = new RequestRunner(_token);
if (requestRunner.IsRequest(m)) {
ThreadPool.QueueUserWorkItem((msg) => {
var response = requestRunner.Request(msg.ToString());
foreach (var content in response)
process.Write(content);
},
m);
} else {
onLine(m);
}
},
new[] {
new KeyValuePair<string,string>("{global-profile}", "\"" + _globalProfileName + "\""),
new KeyValuePair<string,string>("{local-profile}", "\"" + _localProfileName + "\"")
},
process);
_isRunning = false;
stdinForwarder.Abort();
Logger.Write("Running script completed {0}", _file);
}
示例2: 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) => {};
}
示例3: ask
private bool ask(Process proc, string msg)
{
try {
proc.Write(msg);
return true;
} catch {
return false;
}
}
示例4: 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());
}
}
示例5: 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);
}