1

I'm writing an application, and at one point it launches win-acme and needs to pass some parametres to it. I'm successfully opening powershell and launching win-acme, but it doesn't pass arguments to it. So, I have this code:

Process wacsProcess = Process.Start(new ProcessStartInfo
    {
        FileName = @"C:\Windows\System32\WindowsPowershell\v1.0\powershell.exe",
        Arguments = (@"cd C:\inetpub\letsencrypt ; .\wacs.exe ; N"),
        RedirectStandardOutput = true,
        UseShellExecute = false,
        WindowStyle = ProcessWindowStyle.Hidden
   });

File.WriteAllText(".\\OutPutAfterFirstLaunch.txt", 
    wacsProcess.StandardOutput.ReadToEnd());

It opens command-line utility, but doesn't give it the last parametr "N". I guess that is because I'm passing this parametr to the powershell, but it's still working with win-acme. It looks like this:

enter image description here

Is there a way to pass an argument to the command line utility using C#?

hawkstrider
  • 4,141
  • 16
  • 27
  • Should your arguments just be `C:\inetpub\letsencrypt\wacs.exe N`? also, why not just call the exe explicitly? Does it have to be run from a powershell command? – hawkstrider Jun 21 '22 at 20:32
  • Nope, that doesn't work either. Tried to call wacs.exe as a FileName and pass there "N" as an argument. Output is the same as on the sceenshot. – Chicharito Jun 21 '22 at 20:42

2 Answers2

0

This is how this application is designed. It is meant to be interactive for new certificates. Please see the documentation with all of the allowed command-line arguments: https://www.win-acme.com/reference/cli

hawkstrider
  • 4,141
  • 16
  • 27
0

Is there a particular reason that you must launch the process from powershell?

You should be able to read the stdout of the process if you launch it directly the same way as if you were reading the output from your powershell window (the output powershell displays is just the stdout of the process anyways.)

You can also try passing the N parameter with the executable,

Arguments = (@"cd C:\inetpub\letsencrypt ; .\wacs.exe N;"),
Substitute
  • 269
  • 1
  • 9