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. C#
  4. Process.Start is eating spaces

Process.Start is eating spaces

Scheduled Pinned Locked Moved C#
csharpvisual-studiocomdebuggingtools
4 Posts 2 Posters 0 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.
  • M Offline
    M Offline
    Miszou
    wrote on last edited by
    #1

    I am trying to launch a Google search for a specific string from with my application, and this is all working perfectly, until the search string contains quotes. If there are quotes in the search string, then all the spaces inside the string are removed. In the debugger, the string looks like this: http://www.google.com/search?hl=en&q="Just For Laughs Comedy Tour" But when Google gets it, the URL looks like this: http://www.google.com/search?hl=en&q="JustForLaughsComedyTour" If there are no quotes around the search string, then it works perfectly. Running it from the command line doesn't work at all unless I remove the quotes around the search string and place them around the entire command. The code I am using is here: System.Diagnostics.ProcessStartInfo pInfo = new System.Diagnostics.ProcessStartInfo(strCmd, strArgs); pInfo.Verb = "open"; pInfo.ErrorDialog = true; pInfo.WorkingDirectory = strDir; System.Diagnostics.Process.Start(pInfo); I realize that I could probably UrlEncode the string or something, but I am using a generic application launcher thingie that doesn't know anything about the application it is launching - it just calls start on whatever string you pass it. Actually, it is a version of the Visual Studio "External Tools" manager that I wrote[^] as a .NET control, so I don't want it to have to treat URLs differently to standard commands, and I don't want the command to be "IExplore.exe" either. I want it to launch the users default browser based on a URL that I give it. Does anyone know how to workaround this quoted search string weirdness, without having to resort to a special case to fix it? Thanks!

    The StartPage Randomizer - The Windows Cheerleader - Twitter

    F 1 Reply Last reply
    0
    • M Miszou

      I am trying to launch a Google search for a specific string from with my application, and this is all working perfectly, until the search string contains quotes. If there are quotes in the search string, then all the spaces inside the string are removed. In the debugger, the string looks like this: http://www.google.com/search?hl=en&q="Just For Laughs Comedy Tour" But when Google gets it, the URL looks like this: http://www.google.com/search?hl=en&q="JustForLaughsComedyTour" If there are no quotes around the search string, then it works perfectly. Running it from the command line doesn't work at all unless I remove the quotes around the search string and place them around the entire command. The code I am using is here: System.Diagnostics.ProcessStartInfo pInfo = new System.Diagnostics.ProcessStartInfo(strCmd, strArgs); pInfo.Verb = "open"; pInfo.ErrorDialog = true; pInfo.WorkingDirectory = strDir; System.Diagnostics.Process.Start(pInfo); I realize that I could probably UrlEncode the string or something, but I am using a generic application launcher thingie that doesn't know anything about the application it is launching - it just calls start on whatever string you pass it. Actually, it is a version of the Visual Studio "External Tools" manager that I wrote[^] as a .NET control, so I don't want it to have to treat URLs differently to standard commands, and I don't want the command to be "IExplore.exe" either. I want it to launch the users default browser based on a URL that I give it. Does anyone know how to workaround this quoted search string weirdness, without having to resort to a special case to fix it? Thanks!

      The StartPage Randomizer - The Windows Cheerleader - Twitter

      F Offline
      F Offline
      fly904
      wrote on last edited by
      #2

      Did you actually try to google that? Replace ' ' with '+'. http://www.google.co.uk/search?q="Just+For+Laughs+Comedy+Tour"[^]

      hmmm pie

      M 1 Reply Last reply
      0
      • F fly904

        Did you actually try to google that? Replace ' ' with '+'. http://www.google.co.uk/search?q="Just+For+Laughs+Comedy+Tour"[^]

        hmmm pie

        M Offline
        M Offline
        Miszou
        wrote on last edited by
        #3

        fly904 wrote:

        Replace ' ' with '+'.

        I can't, because the code that launches the command doesn't know what sort of command it is. In other words, as far as the launcher knows, these two strings are equivalent and should be treated exactly the same: http://www.google.co.uk/search?q="Just For Laughs Comedy Tour" notepad "Just For Laughs Comedy Tour" Interestingly, if you paste the following command into the Run box in Windows XP it doesn't work either, but if you paste it directly into your browser it works just fine. This leads me to think there's something strange going on inside Windows somwehere. http://www.google.co.uk/search?q="Just For Laughs Comedy Tour" And just for laughs, try these too: firefox http://www.google.com/search?hl=en&q="Just For Laughs Comedy Tour" iexplore http://www.google.com/search?hl=en&q="Just For Laughs Comedy Tour" They both work as expected.

        The StartPage Randomizer - The Windows Cheerleader - Twitter

        F 1 Reply Last reply
        0
        • M Miszou

          fly904 wrote:

          Replace ' ' with '+'.

          I can't, because the code that launches the command doesn't know what sort of command it is. In other words, as far as the launcher knows, these two strings are equivalent and should be treated exactly the same: http://www.google.co.uk/search?q="Just For Laughs Comedy Tour" notepad "Just For Laughs Comedy Tour" Interestingly, if you paste the following command into the Run box in Windows XP it doesn't work either, but if you paste it directly into your browser it works just fine. This leads me to think there's something strange going on inside Windows somwehere. http://www.google.co.uk/search?q="Just For Laughs Comedy Tour" And just for laughs, try these too: firefox http://www.google.com/search?hl=en&q="Just For Laughs Comedy Tour" iexplore http://www.google.com/search?hl=en&q="Just For Laughs Comedy Tour" They both work as expected.

          The StartPage Randomizer - The Windows Cheerleader - Twitter

          F Offline
          F Offline
          fly904
          wrote on last edited by
          #4

          I see your point now after testing it. The only way I found was to 'double escape' the speech marks. I just tried this and it worked perfectly after opening in my default browser (firefox).

          string searchString = "\\\"Just For Laughs Comedy Tour\\\"";
          System.Diagnostics.ProcessStartInfo pInfo = new System.Diagnostics.ProcessStartInfo("http://www.google.co.uk/search?q=" +
          searchString.Replace(" ", "+"));
          pInfo.Verb = "open";
          pInfo.ErrorDialog = true;
          System.Diagnostics.Process.Start(pInfo);

          There's a part of me which hate's seeing spaces in URL's.

          hmmm pie

          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