所以我一直在研究从adb中保存备份的方法,我想出的最好的方法就是:
saveFileDialog1.Title = "Save Backup";
saveFileDialog1.OverwritePrompt = true;
saveFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
var process = Process.Start("CMD.exe", "/c adb backup -apk -all -f"+saveFileDialog1.FileName);
process.WaitForExit();
}
然而,无论我将其保存在何处,都不会将文件置于测试名称下。难道我做错了什么? 我的openFileDialog也是一样的:
openFileDialog1.Title = "Open Backup";
openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
var process = Process.Start("adb.exe", "restore"+openFileDialog1.FileName);
process.WaitForExit();
}
答案 0 :(得分:2)
您的参数格式不正确。您在以下行中缺少空格:
var process = Process.Start("CMD.exe", "/c adb backup -apk -all -f"+saveFileDialog1.FileName);
-f"+saveFileDialog1.FileName
应该是-f "+saveFileDialog1.FileName
。
您还应该将文件名用引号括起来处理文件路径中的空格:
var process = Process.Start("CMD.exe", "/c adb backup -apk -all -f \""+saveFileDialog1.FileName+"\"");