我有一个用C#(.net框架4.0)编写的程序,我有一个用Qt C++编写的主程序,我需要从我的主程序运行这个程序(C#程序),问题是如果我使用QProcess 运行它,没有任何反应,我使用了 Qprocess 的 waitForStarted 和 waitForFinished 成员函数,但已经超时了。
我尝试了Qprocess(start())、system()。 这是我尝试过的:
QProcess p;
p.start(qApp->applicationDirPath()+"/control.exe",{"0000"},QIODevice::ReadWrite);
p.waitForFinished();
QFile fff(qApp->applicationDirPath()+"/control.csv");
if(!fff.exists())
{
/*Error control.csv not exists*/
}
control.exe 从 datagridView 中提取数据并将其存储在 control.csv 文件中,但是当我从 Windows 控制台运行 control.exe 时,不会创建 csv 文件,而 control.exe 可以完美运行。 我如何从 Qt C++ 程序运行它?
PS:我的C#程序是一个控制台应用程序。
谢谢你帮助我。
看来问题出在c#上。 C# 应用程序尝试使用以下代码查找包含 dataGridView 的进程
Process[] process = Process.GetProcessesByName(Path.GetFileNameWithoutExtension("ProcessName"));
if (process.Length == 0) return;
我使用以下代码来提取数据到control.csv
var bw = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ProcessIdProperty, process[0].Id));
// Find the DataGridView in question
var datagrid = bw.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "dataGridView1"));
if (datagrid == null) return;
var loginLines = datagrid.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom));
Console.WriteLine(loginLines.Count);
List<string> colmuns = new List<string>(); ;
List<string> rows = new List<string>(); ;
foreach (AutomationElement loginLine in loginLines)
{
var loginLinesDetails = loginLine.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom));
colmuns.Clear();
for (var i = 0; i < loginLinesDetails.Count; i++)
{
colmuns.Add((loginLinesDetails[i].GetCurrentPattern(ValuePattern.Pattern) as ValuePattern).Current.Value);
}
if(loginLinesDetails.Count > 0)
rows.Add(string.Join(";", colmuns));
}
if(rows.Count > 0)
File.WriteAllText("control.csv", string.Join("\n", rows));
我认为程序没有停止,停在哪里?我真的不知道。