尝试使用字符串来adb命令行 [英] Trying to use a string to adb command line

查看:111
本文介绍了尝试使用字符串来adb命令行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我恳请我的代码中的方向,这是在C#with Android Debug Bridge(ADB)命令在DOS提示符下运行。



< span style ="color:#222222; font-family:Verdana,sans-serif; font-size:14px">该命令基本上从平板电脑读取序列号并将其传输到textBox。在那之前,没问题。但是我需要从这个textBox中复制这个序列号并将
转移到DOS中的新ADB命令来读取电池数据。下面是更好理解的代码,第一个块是获取序列号并将其传输到textBox1:

{

            System.Diagnostics.Process process = new System.Diagnostics.Process();

            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();

            startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

            startInfo.UseShellExecute = false;

            startInfo.RedirectStandardOutput = true;

            startInfo.FileName = "adb.exe";

            startInfo.Arguments = "get-serialno";

            process.StartInfo = startInfo;

            process.Start();

            string output1 = process.StandardOutput.ReadToEnd();

            textBox1.Text = output1;

            process.WaitForExit();

}

第二个块是将命令指向序列号的代码:

startInfo.FileName = "adb.exe";
startInfo.Arguments = "-s " + textBox1.Text + " shell dumpsys battery";
process.StartInfo = startInfo;
process.Start();
string output = process.StandardOutput.ReadToEnd();
richTextBox1.Text = output;
process.WaitForExit();

但我无法识别参数行中的变量。我试图连接,没有成功......我哪里出错了?我已经尝试过,在搜索
我做过:

startInfo.Arguments = String.Format(@"/c adb -s ""{0}"" shell dumpsys battery", output1);
 
startInfo.Arguments = "/c adb -s \"" + output1 + "\" shell dumpsys battery";

startInfo.Arguments = $@"/c adb -s ""{output1}"" shell dumpsys battery";

谢谢!!!

推荐答案

Hello hideki_japs,

Hello hideki_japs,

我不熟练掌握Android技术,以下只是我的一些建议。

I'm not proficient in android technology,the following just is my some suggestion.

1 。你应该查看命令行如果通过手动输入在cmd中运行良好。

1.you should check the command line if works well in cmd by manual input.

2 。您可以尝试使用
替代代码
 如下所示。

2.you could try to use alternative code like below.

Process.Start(FilePath, @"-a arg1 -b arg2");

3 。有一个 
好​​例子
关于如何向一个过程发送一系列命令。

3.there is a  good example for how to send series of commands to a process.

真诚地,

neil hu


这篇关于尝试使用字符串来adb命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆