我的代码片段如下:
静态空LaunchCommandLineApp() {
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "adb.exe ";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments =@"logcat > C:\adb\out.txt";
Process exeProcess = Process.Start(startInfo);
}我的控制台中的错误是:
按任意键继续。。。/system/bin/sh:无法创建C:\adb\out.txt:只读文件系统
它似乎是试图重定向和保存在手机上的输出。
当我试图从cmd运行以下代码时,根本没有问题:
adb.exe logcat > C:\adb\out.txt
我知道我可以在批处理脚本中执行这个操作,但是我会丢失一个指向adb.exe进程的链接,如果存在多个adb.exe进程,我将无法直接关闭它。
如能提供任何协助,将不胜感激。
发布于 2013-11-02 08:18:02
问题是,如果由>处理,则重定向操作数( cmd.exe )。如果不涉及cmd,则不能使用它。你的选择是
(1)如您所说,运行批处理文件,不引用亚行进程。
(2)直接运行cmd。您的命令应该看起来像
cmd.exe /c "adb.exe logcat > c:\adb\out.txt"
这将移除批处理文件,但您将再次失去对adb.process的引用。
(3)处理重定向。使用startInfo.RedirectStandardOutput = true;获取adb命令的输出句柄,然后调用
string adbOutput = exeProcess.StandardOutput.ReadToEnd();https://stackoverflow.com/questions/19735393
复制相似问题