4

I'm trying to figure out how to get cmd.exe (command prompt) to display outputs in different language than the one installed in the system.

I'll use a simple command as example. If I type the command

date

the output will be:

Data corrente: 07/05/2018

Immettere la nuova data: (gg-mm-aa)

That's because the Windows installed on my system is set to Italian.

I would like, in my application, to execute commands through CMD.exe and parse their output. I already know how to do that, but the problem is that if my application is executed on non-italian Windows systems the application won't work because it's based on italian strings (eg. I search for "Data corrente" string, but if Windows is set to other languages the string won't be found).

I need to generate outputs in a fixed language regardless of the language installed on the system.

Using the example above, typing the "date" command I would like to get the following output in ALL systems, including italian ones:

The current date is: 07/05/2018

Enter the new date: (gg-mm-aa)

Thanks.

Community
  • 1
  • 1
robytur
  • 97
  • 1
  • 8
  • 1
    https://wandersick.blogspot.com/p/change-non-english-command-line.html not sure if this still works with the latest OS version though – Steve May 07 '18 at 14:50
  • Its more a culture setting. Check this [link](https://msdn.microsoft.com/en-us/library/5hh873ya(v=vs.100).aspx) for further info – H.Mikhaeljan May 07 '18 at 14:54
  • It's worth nothing that `date` is a particulary troublesome example because its output depends not merely on the language, but also on the actual regional settings (`gg-mm-aa` is not the format used on most systems, but even on my US English Windows the short date format is set to `yy-mm-dd`). I assume/hope you're not actually invoking `date`, though... – Jeroen Mostert May 07 '18 at 14:56
  • If possible, don't use built-in commands that localize at all. Write C# code that does what you want, or write a PowerShell script that formats its output in a manner that's independent of the locale settings and invoke that. There are very few things that can be only be done conveniently by invoking built-in commands, and even fewer that can't be done in any other way. – Jeroen Mostert May 07 '18 at 15:03
  • The "date" command is just an example, I don't use that (I know more convenient ways to manage DateTime than using cmd). The matter is if it's possible to show output in different language than the native one. – robytur May 07 '18 at 17:21
  • @Steve this would be nice but it requires admin rights and I'd need something less invasive. Also, the command "chcp 437" doesn't work (it still displays output in Italian). – robytur May 07 '18 at 18:20
  • As far as I know what are you trying to do is not possible without some _escamotage_ to fool the OS like explained in the link above. There is this question posted sometime ago but I don't know if it is of any help https://stackoverflow.com/questions/9530350/changing-the-region-and-language-os-setting-programmatically – Steve May 07 '18 at 18:28

1 Answers1

0

Try this :

Console.Out.WriteLine($"The current date is: {DateTime.Now.ToShortDateString()}");
var currentCulture = Thread.CurrentThread.CurrentCulture;
Console.Out.Write($"Enter the new date: {currentCulture.DateTimeFormat.ShortDatePattern}");
Oilid
  • 141
  • 1
  • 8