Re: C# console application executing command line commands?

  • From: "Jacob Kruger" <jacobk@xxxxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Sat, 7 Aug 2010 22:54:15 +0200

Ok, FWIW, seems simplest trick is to use the System.Diagnostics.Process to in fact execute a batch file:



System.Diagnostics.Process proc = new System.Diagnostics.Process();

proc.EnableRaisingEvents = false;

proc.StartInfo.FileName = stAppPath + "playlist.bat";

proc.StartInfo.Arguments = fils[I].Substring(2, (fils[I].Length - 2));

proc.Start();

proc.WaitForExit();



fils[] string array is something am populating using System.IO.Directory.GetFiles(), and stAppPath is assigned a value from

System.IO.Directory.GetCurrentDirectory() fwiw;


Only real issue now is that if the argument strings have spaces in them, they get seen as multiple arguments, so unless can confirm if can do a form of search/replace within batch file, I'll do something like specify up to around 5-10 of them in case:
echo %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 > zFile.txt

And that should work around the spacing issue, but let's see...might just go over to actual windows app, and stream playlist file contents myself from within code, but anyway...

Other thing remembered is that within the actual batch file/command line instance while > will redirect to a newly created/replaced file, >> will in fact append to an existing file.

You can also easily enough use System.Console.WriteLine to output status messages, but jaws, for example doesn't read them to me automatically.

Stay well

Jacob Kruger
Blind Biker
Skype: BlindZA
'...fate had broken his body, but not his spirit...'


__________ Information from ESET NOD32 Antivirus, version of virus signature 
database 5348 (20100806) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com



__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind

Other related posts: