Re: C# console application executing command line commands?

  • From: "Martin Slack" <m.g.slack@xxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Sat, 7 Aug 2010 22:35:58 +0100

If you can guarantee that your multiple arguments will always represent one string, then %* will pick them all up within the batch file.


If you want more than one argument with spaces in them, you are going to have to descend into the depths of the DOS FOR loop.

 Good Luck

 Martin


----- Original Message ----- From: "Jacob Kruger" <jacobk@xxxxxxxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Saturday, August 07, 2010 9:54 PM
Subject: Re: C# console application executing command line commands?


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


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

Other related posts: