Re: C# console application executing command line commands?

  • From: "Jacob Kruger" <jacobk@xxxxxxxxxxxxxx>
  • To: <ProgrammingBlind@xxxxxxxxxxxxx>
  • Date: Sat, 7 Aug 2010 23:55:37 +0200

Will check it out, etc., and the only real issue is would have liked to also
pass an argument relating to output file name, but, OTOH, since that's the
only other argument would have passed, maybe I'll do something like use a
standard file name that's unlikely to clash with anything else, and then
just rename it after generation - easy enough.

And, yes %* works fine - just tried it out now.

Thanks

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

----- Original Message ----- From: "Martin Slack" <m.g.slack@xxxxxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Saturday, August 07, 2010 11:35 PM
Subject: Re: C# console application executing command line commands?


 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


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

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com





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

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




__________ 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: