Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
Command prompt not opening but executing the command in .Net

I am new to .net, I have a task in which I need to open command prompt from a particular directory and then execute few commands in it. All this needs to be done by code. I tried the similar for testing purpose in below code

            var res = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
            Process cmd = new Process();
            cmd.StartInfo.WorkingDirectory = @"E:\";
            cmd.StartInfo.FileName = "cmd.exe";
            cmd.StartInfo.RedirectStandardInput = true;
            cmd.StartInfo.RedirectStandardOutput = true;
            cmd.StartInfo.CreateNoWindow = true;
            cmd.StartInfo.UseShellExecute = false;
            cmd.Start();

            cmd.StandardInput.WriteLine("mkdir test");
            cmd.StandardInput.Flush();
            cmd.StandardInput.Close();
            cmd.StandardOutput.ReadToEnd();
            cmd.WaitForExit();

The problem is, it is making directory as the command says but command prompt is not opening. For the actual task the command is different in which I am starting the server. So for that the command prompt needs to open and show the details of server.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The issue is this line:

cmd.StartInfo.CreateNoWindow = true;

I feel like the name of that property is pretty self explanitory, but here is what the MSDN entry about it says:

Property Value Boolean true if the process should be started without creating a new window to contain it; otherwise, false. The default is false.

Also, the line regarding shell execute is also likely to prevent a window from appearing:

cmd.StartInfo.UseShellExecute = false;

I suggest you look into all the properties of StartInfo that you're using here because this looks like you copy pasted code without understanding it at all.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!