1

I want to run mc.exe using by PowerShell as I write below.

How can I do that? I tried to add in Filename but it doesn't work.

var mcExe = @"C:\Users\developer\Desktop\Example\mc.exe ";

var proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = mcExe;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.Verb = "runas";
proc.StartInfo.Arguments = String.Format("{0}{1}{2}", "./mc alias set myCloud http://localhost:9000", "admin", "123456");
proc.Start();
2
  • Could you check if the proc is running and print the ExitCode if the proc has exited ? Commented Apr 8, 2022 at 6:23
  • I changed there is no error but doesn't executing, Arguments = @"@('cd C:\Users\developer\Desktop\Example\', './mc alias set myCloud localhost:9000', 'admin', '12345678', './mc admin user add myCloud testwashere 12345678')", Commented Apr 8, 2022 at 7:15

2 Answers 2

1

Did you try set proc.StartInfo.UseShellExecute = true; ? Because this property responsible for using powershell

Sign up to request clarification or add additional context in comments.

Comments

1

Starting Powershell directly might work for you, e.g. :

using System.Diagnostics;

ProcessStartInfo startInfo = new ProcessStartInfo
{
    FileName = @"powershell.exe",
    Arguments = @"& 'C:\Users\developer\Desktop\Example\mc.exe' @('./mc alias set myCloud http://localhost:9000', 'admin', '123456')",
    RedirectStandardOutput = true,
    RedirectStandardError = true,
    UseShellExecute = false,
    CreateNoWindow = true,
    Verb = "runas",
};
Process process = new Process();
process.StartInfo = startInfo;
process.Start();

string output = process.StandardOutput.ReadToEnd();

string errors = process.StandardError.ReadToEnd();

7 Comments

Thanks for your helping but I got same error like below : "mc.exe: <ERROR> ./mc alias set myCloud http://localhost:9000 is not a recognized command.
could you provide that script? so we can try it on our local?
when i wrote ./mc alias set myCloud localhost:9000 that in powershell there is no problem its working fine. but when we tried to work in c# we are getting error
With your code which you send me, proc is working. But I did not understand why saying is not a recognized command.
yeah, not sure, without having the script it's hard to guess what's wrong...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.