Tutorial :Redirecting Command-line Arguments for Bootstrapping


I am trying to rewrite the following program in C instead of C# (which is less portable). It is obvious that "int system ( const char * command )" will be necessary to complete the program. Starting it with "int main ( int argc, char * argv[] )" will allow getting the command-line arguments, but there is still a problem that is difficult to understand. How do you successfully escape arguments with spaces in them? In the program below, arguments with spaces in them (example: screensaver.scr "this is a test") will be passed to the script as separate arguments (example: screensaver.scr this is a test) and could easily cause problems.

namespace Boids_Screensaver  {      static class Program      {          [STAThread]          static void Main(string[] args)          {              System.Diagnostics.Process python = new System.Diagnostics.Process();              python.EnableRaisingEvents = false;              python.StartInfo.FileName = "C:\\Python31\\pythonw.exe";              python.StartInfo.Arguments = "boids.pyw";              foreach (string arg in args)              {                  python.StartInfo.Arguments += " " + arg;              }              python.Start();          }      }  }  


The correct way to do this under windows is to use _spawnv

Its equivalent under unix like OSes is fork() followed by execv.


Windows is all messed up. Every program has its own rules.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »