Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7427925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:39:43+00:00 2026-05-29T08:39:43+00:00

I’m trying to run a command in cmd using C# and am having some

  • 0

I’m trying to run a command in cmd using C# and am having some difficulties. I’d like to be able to write the command to the cmd console so I can see what it’s trying to run (I think there’s some issue with the quotes or something, so if I could see the actual string in the command line, I’d be able to see exactly what the problem is). My code looks like this:

var processStartInfo  = new ProcessStartInfo("cmd", "/c"+commandString);
processStartInfo.CreateNoWindow = true;
Process.Start(processStartInfo);

So basically, I just want to see the string commandString written in the console. Any help would be greatly greatly appreciated.

string CommandLineString = @"""C:\Program Files\Microsoft SQL Server\100\Tools\Binn\bcp.exe"" ""SELECT * FROM table where date >= '2009-01-01'"" queryout  ""C:\Data\data.dat"" -S DBSW0323 -d CMS -n -T";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:39:44+00:00Added an answer on May 29, 2026 at 8:39 am

    In this case, the problem is probably just your lack of a space after “/c”.

    var processStartInfo  = new ProcessStartInfo("cmd", "/c " + commandString);
    

    As for viewing in a command window, instead, you will probably be better off inspecting the Arguments property of your processStartInfo instance.

    EDIT

    Taking into account the command line details you posted, I believe this is what your issue is. Check out the following from cmd help:

    If /C or /K is specified, then the remainder of the command line after
    the switch is processed as a command line, where the following logic is
    used to process quote (“) characters:

    1. If all of the following conditions are met, then quote characters
      on the command line are preserved:

      • no /S switch
      • exactly two quote characters
      • no special characters between the two quote characters,
        where special is one of: &<>()@^|
      • there are one or more whitespace characters between the
        the two quote characters
      • the string between the two quote characters is the name
        of an executable file.

    Since you are using /c, you have quote and special char issues still. Try wrapping your entire commandString in a set of quotes.

    Take this simple example for instance (creating temp.txt manually of course):

    string commandString = @"""C:\WINDOWS\Notepad.exe"" ""C:\temp.txt""";
    var processStartInfo = new ProcessStartInfo("cmd", "/c " + commandString);
    

    The command line to be executed will be: /c "C:\WINDOWS\Notepad.exe" "C:\temp.txt", but this will fail since “C:\temp.txt” is not an executable.

    If you wrap the whole thing in one last set of quotes, you should see the intended result:

    string commandString = @"""""C:\WINDOWS\Notepad.exe"" ""C:\temp.txt""""";
    var processStartInfo = new ProcessStartInfo("cmd", "/c " + commandString);
    

    Resulting in a command line of: /c ""C:\WINDOWS\Notepad.exe" "C:\temp.txt"" and ultimately opening notepad with your test file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
We're building an app, our first using Rails 3, and we're having to build
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.