2

I am try to send the string as command line argument to my python script as follow:

var cmdToBeExecute = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + "\\myScript.py";
            var start = new ProcessStartInfo
            {
                FileName = "C:\\Python27\\python.exe",
                Arguments = string.Format("{0} {1}", cmdToBeExecute, "Rahul done good"),
                UseShellExecute = false,
                RedirectStandardOutput = true,
                CreateNoWindow = true
            };

and i am try to read the command line argument and display it in python as:

import sys
print sys.argv[1]

But, I get only the first word "Rahul" as output. Please help me to send string as command parameter argument to my python script.

m2pathan
  • 360
  • 2
  • 17
  • the others are in the `sys.argv[2]` and `sys.argv[3]` try to print them all. You may use for loop, for instance – Ian Feb 16 '16 at 06:45

1 Answers1

5

You should pass your string inside double quotes if it contains spaces:

Arguments = string.Format("{0} {1}", cmdToBeExecute, "\"Rahul done good\""),

This is not specific to C#; you should use quotes even if you run it from the command line:

python myscript.py "Rahul done good"
Selcuk
  • 57,004
  • 12
  • 102
  • 110