[英]cmd.exe and adb command
您好,我通过 c# 使用 cmd 命令有一些问题,例如我在 cmd.exe 中手动执行命令
//command1 to pick directory
cd C:\Users\NewSystem\source\repos
//command2 command to send file to emulator
adb -s emulator-5554 push Debug\funnels\01\01.mp4 /sdcard/Download
我在 C# 中测试的代码是,它不能正常工作,完全没有向 android 模拟器发送任何内容
Process cmd = new Process();
cmd.StartInfo.FileName = "cmd.exe";
cmd.StartInfo.WorkingDirectory = @"C:\Users\NewSystem\source\repos\";
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = false;
cmd.StartInfo.CreateNoWindow = false;
cmd.StartInfo.UseShellExecute = false;
cmd.Start();
cmd.StandardInput.WriteLine("adb -s emulator-5554 push Debug\funnels\01\01.mp4 /sdcard/Download");
cmd.StandardInput.Flush();
cmd.StandardInput.Close();
cmd.WaitForExit();
要启动cmd.exe
并让它执行命令,您需要传递/c
(执行命令并退出)或/k
(执行命令并保持)...
cmd /c adb -s emulator-5554 push Debug\funnels\01\01.mp4 /sdcard/Download
不过,您不需要让cmd.exe
启动adb.exe
; 直接启动adb.exe
即可。
至于您的 C# 代码, StandardInput
用于写入进程的stdin
流,这不是您想要的。 通过命令行参数的方法是使用ArgumentList
(.NET(核心)2.1+)或Arguments
(所有的.NET Framework /核心版本)的性能ProcessStartInfo
...
// Dispose cmd when finished
using (Process cmd = new Process())
{
// The full executable path is required if its directory is not in %PATH%
cmd.StartInfo.FileName = @"C:\Users\NewSystem\source\repos\adb.exe";
cmd.StartInfo.Arguments = @"-s emulator-5554 push ""Debug\funnels\01\01.mp4"" ""/sdcard/Download""";
cmd.StartInfo.WorkingDirectory = @"C:\Users\NewSystem\source\repos\";
cmd.StartInfo.CreateNoWindow = false;
cmd.StartInfo.UseShellExecute = false;
cmd.Start();
cmd.WaitForExit();
}
我将Arguments
设置为逐字字符串,其中引用了最后两个参数,只是为了说明如果任一路径包含空格,您将如何执行此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.