Read return values from the command line

morpheus93

Client
Регистрация
25.01.2012
Сообщения
1 058
Благодарностей
244
Баллы
63
Helllo,

how can I get the output (return values) from the command line in ZP, after I executed an command via "Own code - Run programm"?

E.g. I run myprogramm.exe --verifyaddress "address to verify" and in the cmd output it gives me a json string in return. How can I access this return string from ZP and store the values to variables?

Thank you.
 

EtaLasquera

Client
Регистрация
02.01.2017
Сообщения
526
Благодарностей
112
Баллы
43
You must use C#
Код:
Process P = Process.Start(sPhysicalFilePath, Param);
P.WaitForExit();
int result = P.ExitCode;
 
  • Спасибо
Реакции: morpheus93

morpheus93

Client
Регистрация
25.01.2012
Сообщения
1 058
Благодарностей
244
Баллы
63
Thank you SOS Cartões for your appreciated help :-)

Your C# works well for returning an integer value (exit code) to ZP and access its value from there. In my special case I need a complete JSON string to be returned to the ZP-project. But I have found a solution in the meantime:

Код:
Process process = new Process
{
  StartInfo =
  {
  UseShellExecute = false,
  RedirectStandardOutput = true,
  RedirectStandardError = true,
  CreateNoWindow = true,
  FileName = "pathe to .exe or name in PATH",
  Arguments = "the needed arguments e.g. --verify-address xyz"
  }
};
process.Start();
process.WaitForExit();
if(process.HasExited)
{
  string output = process.StandardOutput.ReadToEnd();
  project.Variables["returnFromCmd"].Value = output;
}
Hope this helps you also :-)
 

EtaLasquera

Client
Регистрация
02.01.2017
Сообщения
526
Благодарностей
112
Баллы
43
Oh I don't know what you want to get :p
I break my head to take the second line of a command, here is the solution if you need take 2nd line in a near future.
That code execute a command a lot of times, if you have a table with 300 lines to solve, that code will execute the command 300 times and will show the percentage of process in zenno log.

Код:
var tbl = project.Tables["dados"];
int i = 0;
decimal k = 1;
decimal l = tbl.RowCount;
while (i < tbl.RowCount){
  project.SendInfoToLog("Convertendo nome do arquivo..."+Math.Round((k/l)*100,2)+"%concluído...",true);
  System.Diagnostics.Process p = new System.Diagnostics.Process();
  p.StartInfo.UseShellExecute = false;
  p.StartInfo.CreateNoWindow = true;
  p.StartInfo.RedirectStandardOutput = true;
  p.StartInfo.RedirectStandardError = true;
  p.EnableRaisingEvents = true;
  p.StartInfo.WorkingDirectory = "C:\\TEMP\\bin\\";
  p.StartInfo.FileName = "C:\\TEMP\\bin\\xlstocsv.exe";
  p.StartInfo.Arguments = tbl.GetCell("A",i)+" "+project.Variables["cod"].Value;
  p.Start();
  p.BeginOutputReadLine();
  string msg = p.StandardError.ReadToEnd();
  p.WaitForExit();
  int j = msg.IndexOf(".",0) -5;
  tbl.SetCell("B",i,msg.Substring(5,j));
  i++;
  k++;
}
 
  • Спасибо
Реакции: morpheus93

morpheus93

Client
Регистрация
25.01.2012
Сообщения
1 058
Благодарностей
244
Баллы
63
Your code looks great :-) Thank you very much. I'm sure this can be very useful for me in the near future. :az:
 

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)