i want to pass multiple string variable from my program C# to Python script.
This is my function in C# where i call a file InsertSemantic.py and i want to pass there 9 arguments ( nome, formVerb, contesto ecc...)
private void insertDatabase(String nome, String formVerb, String contesto, String sinonimi, String significato, String class_gramm, String class_prag, String class_sem, String retorico)
{
string arg = string.Format(@"C:\Users\marco\eclipse-workspace\my_project\src\InsertSemantic.py {0}", nome, formVerb, contesto, sinonimi, significato, class_gramm, class_prag, class_sem, retorico);
try
{
Process p1 = new Process();
p1.StartInfo = new ProcessStartInfo(@"C:\Python27\python.exe", arg);
p1.StartInfo.UseShellExecute = false;
p1.StartInfo.RedirectStandardOutput = true;
p1.Start();
p1.WaitForExit();
}
catch (Exception ex)
{
Console.WriteLine("There is a problem in your Python code: " + ex.Message);
}
Console.WriteLine("Press enter to exit...");
Console.ReadLine();
}
I have write in InsertSemantic.py this row:
import sys
nome= sys.argv[1]
formVer=sys.argv[2]
contesto= sys.argv[3]
sinonimi=sys.argv[4]
significato=sys.argv[5]
gramm=sys.argv[6]
prag=sys.argv[7]
sem=sys.argv[8]
retorico=sys.argv[9]
but with a simple print i have seen that i receive just ONE argument (nome) and the other argument doesn't pass... someone can help me?
string arg = string.Format(@"C:\Users\marco\eclipse-workspace\my_project\src\InsertSemantic.py {0}", nome, formVerb, contesto, sinonimi, significato, class_gramm, class_prag, class_sem, retorico);
is only taking the first format value with {0}. You need to include the rest of the values as well, eg. {0},{1},{2} et cetera.
string arg = string.Format(@"C:\Users\marco\eclipse-workspace\my_project\src\InsertSemantic.py {0} {1} {2} {3} {4} {5} {6} {7} {8}", nome, formVerb, contesto, sinonimi, significato, class_gramm, class_prag, class_sem, retorico);
the above should include the rest of the parameters to add to your formatted string.
In the future, you can solve this by stepping through your code in the debugger and you would notice that when arg is assigned to, only the first of your parameters gets passed, indicating that the problem is at the time of assignment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With