如何在C#中使用awk命令
public class CmdHelper
{
public static string StartCmd(string commandLine)
{
commandLine = commandLine.Trim().TrimStart('&') + "&exit";
string outputMsg = "";
Process pro = new Process();
pro.StartInfo.FileName = "cmd.exe";
pro.StartInfo.UseShellExecute = false;
pro.StartInfo.RedirectStandardError = true;
pro.StartInfo.RedirectStandardInput = true;
pro.StartInfo.RedirectStandardOutput = true;
pro.StartInfo.CreateNoWindow = false;
pro.Start();
pro.StandardInput.WriteLine(commandLine);
pro.StandardInput.AutoFlush = true;
pro.StartInfo.StandardErrorEncoding = Encoding.UTF8;
pro.StartInfo.StandardOutputEncoding = Encoding.UTF8;
outputMsg += pro.StandardOutput.ReadToEnd();
pro.WaitForExit();
pro.Close();
return outputMsg;
}
public static void CommitBundleToSvn()
{
string folderPath = EditorConst.BundlesPath + VEngine.Editor.Builds.Settings.GetPlatformName();
string command = "svn status " + folderPath;
string regaxPattern = ".*&exit";
string output = "";
string[] regexRes = {};
command = "svn st " + folderPath+ " | awk \"{if ($1 == \\\"?\\\") {print $2} }\"";
output = CmdHelper.StartCmd(command);
UnityEngine.Debug.LogError(command);
UnityEngine.Debug.LogError(output);
}
execute命令:
("svn st " + folderPath+ " | awk \"{if ($1 == \\\"?\\\") {print $2} }\"")
在Windows CMD
中,CMD可以获取返回消息。
现在,我称为commitbundletosvn()。但是CMD不会退出。
如果命令是“ SVN状态” + FolderPath,则可以预期。
public class CmdHelper
{
public static string StartCmd(string commandLine)
{
commandLine = commandLine.Trim().TrimStart('&') + "&exit";
string outputMsg = "";
Process pro = new Process();
pro.StartInfo.FileName = "cmd.exe";
pro.StartInfo.UseShellExecute = false;
pro.StartInfo.RedirectStandardError = true;
pro.StartInfo.RedirectStandardInput = true;
pro.StartInfo.RedirectStandardOutput = true;
pro.StartInfo.CreateNoWindow = false;
pro.Start();
pro.StandardInput.WriteLine(commandLine);
pro.StandardInput.AutoFlush = true;
pro.StartInfo.StandardErrorEncoding = Encoding.UTF8;
pro.StartInfo.StandardOutputEncoding = Encoding.UTF8;
outputMsg += pro.StandardOutput.ReadToEnd();
pro.WaitForExit();
pro.Close();
return outputMsg;
}
public static void CommitBundleToSvn()
{
string folderPath = EditorConst.BundlesPath + VEngine.Editor.Builds.Settings.GetPlatformName();
string command = "svn status " + folderPath;
string regaxPattern = ".*&exit";
string output = "";
string[] regexRes = {};
command = "svn st " + folderPath+ " | awk \"{if ($1 == \\\"?\\\") {print $2} }\"";
output = CmdHelper.StartCmd(command);
UnityEngine.Debug.LogError(command);
UnityEngine.Debug.LogError(output);
}
Execute command:
("svn st " + folderPath+ " | awk \"{if ($1 == \\\"?\\\") {print $2} }\"")
In windows cmd
, cmd could get return message.
Now I call the CommitBundleToSvn(). but the cmd will not exit.
If the command is "svn status " + folderPath, it is expected.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
另一个选项是在这种情况下不使用
awk
,然后做:Another option is to not use
awk
in this case, and do: