Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Keeping Command Console Open After Running Process

Keeping Command Console Open After Running Process

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharptoolsquestiondiscussionworkspace
5 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tristan Rhodes
    wrote on last edited by
    #1

    Hi Guys, I am running a command line application from inside my C# code, however it's failing and exiting out immediately. I'm trying to get the window to stay open after the program has finished running. I've tried the following: This opens the window, runs the script, fails and closes it: Process.Start(@"C:\Program Files\Inno Setup 5\iscc.exe", @"%dir%\MyInstallScript.iss"); This opens the window, keeps it open, and says: 'C:\Program' is not recognized as an internal or external command, operable program or batch file.: Process.Start("cmd.exe", "/k \"C:\\Program Files\\Inno Setup 5\\iscc.exe\" \"%dir%\\MyInstallScript.iss\""); Second one seems a bit weird, as i am wrapping everything in quotes as expected. Not sure what's going on here. Do i need to do something crazy like nesting the quotes? And if so, how would i do that? Any thoughts? Regards Tris

    ------------------------------- Carrier Bags - 21st Century Tumbleweed.

    A Q 2 Replies Last reply
    0
    • T Tristan Rhodes

      Hi Guys, I am running a command line application from inside my C# code, however it's failing and exiting out immediately. I'm trying to get the window to stay open after the program has finished running. I've tried the following: This opens the window, runs the script, fails and closes it: Process.Start(@"C:\Program Files\Inno Setup 5\iscc.exe", @"%dir%\MyInstallScript.iss"); This opens the window, keeps it open, and says: 'C:\Program' is not recognized as an internal or external command, operable program or batch file.: Process.Start("cmd.exe", "/k \"C:\\Program Files\\Inno Setup 5\\iscc.exe\" \"%dir%\\MyInstallScript.iss\""); Second one seems a bit weird, as i am wrapping everything in quotes as expected. Not sure what's going on here. Do i need to do something crazy like nesting the quotes? And if so, how would i do that? Any thoughts? Regards Tris

      ------------------------------- Carrier Bags - 21st Century Tumbleweed.

      A Offline
      A Offline
      Alan N
      wrote on last edited by
      #2

      Hi, This looks straightforward but like you I cannot get it to work. I read the MSDN page on cmd.exe and the section on processing quotation marks left me completely baffled. http://technet.microsoft.com/en-us/library/bb490880.aspx[^] As with much of the stuff on MSDN it is missing a decent example. Can you understand what the /s switch does? May be I'm just thick but I don't think "Modifies the treatment of string after /c or /k" is an explanation. A simple solution or workaround for your problem would be to start a batch file, e.g.

      Process.Start("setup.cmd", "\"%dir%\\MyInstallScript.iss\"");

      where setup.cmd is

      @echo off
      C:\Program Files\Inno Setup 5\iscc.exe "%~1"
      pause

      If you are concerned that the batch file could be modified by the user you could always have your program generate it just before it is required. Alan.

      1 Reply Last reply
      0
      • T Tristan Rhodes

        Hi Guys, I am running a command line application from inside my C# code, however it's failing and exiting out immediately. I'm trying to get the window to stay open after the program has finished running. I've tried the following: This opens the window, runs the script, fails and closes it: Process.Start(@"C:\Program Files\Inno Setup 5\iscc.exe", @"%dir%\MyInstallScript.iss"); This opens the window, keeps it open, and says: 'C:\Program' is not recognized as an internal or external command, operable program or batch file.: Process.Start("cmd.exe", "/k \"C:\\Program Files\\Inno Setup 5\\iscc.exe\" \"%dir%\\MyInstallScript.iss\""); Second one seems a bit weird, as i am wrapping everything in quotes as expected. Not sure what's going on here. Do i need to do something crazy like nesting the quotes? And if so, how would i do that? Any thoughts? Regards Tris

        ------------------------------- Carrier Bags - 21st Century Tumbleweed.

        Q Offline
        Q Offline
        qmartens
        wrote on last edited by
        #3

        The entire command line after /k needs to be in quotes like so: Process.Start("cmd.exe", "/k \"\"C:\\Program Files\\Inno Setup 5\\iscc.exe\" \"%dir%\\MyInstallScript.iss\"\""); Note the extra quote characters at the start and the end of the argument after /k.

        Eagles my fly, but weasels don't get sucked into jet engines.

        A T 2 Replies Last reply
        0
        • Q qmartens

          The entire command line after /k needs to be in quotes like so: Process.Start("cmd.exe", "/k \"\"C:\\Program Files\\Inno Setup 5\\iscc.exe\" \"%dir%\\MyInstallScript.iss\"\""); Note the extra quote characters at the start and the end of the argument after /k.

          Eagles my fly, but weasels don't get sucked into jet engines.

          A Offline
          A Offline
          Alan N
          wrote on last edited by
          #4

          Oh I get it, I would never have thought of trying out that many quotes although after unescaping everything it is clear that there is now only one string after the /k. cmd.exe /k ""C:\Program Files\Inno Setup 5\iscc.exe" "%dir%\MyInstallScript.iss"" Alan.

          1 Reply Last reply
          0
          • Q qmartens

            The entire command line after /k needs to be in quotes like so: Process.Start("cmd.exe", "/k \"\"C:\\Program Files\\Inno Setup 5\\iscc.exe\" \"%dir%\\MyInstallScript.iss\"\""); Note the extra quote characters at the start and the end of the argument after /k.

            Eagles my fly, but weasels don't get sucked into jet engines.

            T Offline
            T Offline
            Tristan Rhodes
            wrote on last edited by
            #5

            Ah. Thank you. It's infuriating, i feel i was so close on my own! ^^

            ------------------------------- Carrier Bags - 21st Century Tumbleweed.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups