Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Launch http page/string from DOS/Command Line?  (Read 7542 times)

0 Members and 1 Guest are viewing this topic.

omega1

    Topic Starter


    Rookie

    • Experience: Beginner
    • OS: Unknown
    Launch http page/string from DOS/Command Line?
    « on: May 12, 2011, 02:50:50 PM »
    Hi all,

    Am having a bit of a brain block...

    I have two .txt files which I need to join together in DOS and then launch the content of these joined files as a URL.

    So, imagine that a.txt contains "http://www.mysite.com" and b.txt contains "/mypage.html". I would like to join them via DOS command line and the open this in a browser.

    All I can get at the moment is that the .txt opens inside the browser as a page, but I need it to actually load the URL, not display the URL in the page as a text file.

    I must be doing soemthing wrong, can anyone point me in the right direction?

    Thanks in advance!

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Launch http page/string from DOS/Command Line?
    « Reply #1 on: May 12, 2011, 03:04:29 PM »
    Here is one way to invoke a URL from the command line.
    Code: [Select]
    D:\>start firefox.exe "www.mozilla.org"This is documented on the Mozilla site. Except they don't tell you that you have to use the 'start' command.

    omega1

      Topic Starter


      Rookie

      • Experience: Beginner
      • OS: Unknown
      Re: Launch http page/string from DOS/Command Line?
      « Reply #2 on: May 12, 2011, 03:08:17 PM »
      Hi, yes, tried that, but it wont work in my situation, hwere I need it to launch the URL that is in my .txt file, even if i change the extension to .html... thanks

      Geek-9pm


        Mastermind
      • Geek After Dark
      • Thanked: 1026
        • Gekk9pm bnlog
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: Launch http page/string from DOS/Command Line?
      « Reply #3 on: May 12, 2011, 03:26:06 PM »
      You need to show us what you are doing.
      Do you want Firefox to got to a URL inside of a file?
      That can be done, if you insist. But it is  awkward and requires awk.
      First,  show your code and others here can recommend a method that works well and is easy to use.

      omega1

        Topic Starter


        Rookie

        • Experience: Beginner
        • OS: Unknown
        Re: Launch http page/string from DOS/Command Line?
        « Reply #4 on: May 12, 2011, 03:33:11 PM »
        I have no real code...

        Yes, I need Firefox (or IE) to open the URL inside the content of the c.txt file (I can rename c.txt to c.html or anything else, that isnt an issue).

        I am adding the contents of a.txt to b.txt with
        Code: [Select]
        copy a.txt + b.txt c.txt
        a.txt never varies, b.txt does vary, but thats not relevant.

        I then need to launch the URL that is inside c.txt with either Firefox or IE.

        Thanks

        Sidewinder



          Guru

          Thanked: 139
        • Experience: Familiar
        • OS: Windows 10
        Re: Launch http page/string from DOS/Command Line?
        « Reply #5 on: May 12, 2011, 03:40:29 PM »
        You can do this with simple batch language and build the url in memory:

        Code: [Select]
        @echo off

        for /f "tokens=* delims=" %%i in (a.txt) do set part1=%%i
        for /f "tokens=* delims=" %%i in (b.txt) do set part2=%%i

        set url=%part1%%part2%
        firefox "%url%"

        You might need to fixup the paths for a.txt, b.txt and Firefox. You are not restricted to Firefox, use whatever browser yu have with a fully qualified path.

        Good luck.  8)

        You don't need awk or any other 3rd party program. You also do not need to use the start command with the browser.
        The true sign of intelligence is not knowledge but imagination.

        -- Albert Einstein

        omega1

          Topic Starter


          Rookie

          • Experience: Beginner
          • OS: Unknown
          Re: Launch http page/string from DOS/Command Line?
          « Reply #6 on: May 13, 2011, 01:09:32 AM »
          Hi Sidewinder,

          Thanks for your help. I have copied that into a .bat file and changed the paths and it nearly works, I have the following problem:

          a.txt contains the following:
          Code: [Select]
          http://IP/admin.cgi?pass=password&mode=updinfo&song=and I think this line:
          Code: [Select]
          for /f "tokens=* delims=" %%i in (a.txt) do set part1=%%iis causing it to cut it off at the '&' symbol, as it is giving me the following error:
          Code: [Select]
          Invalid parameter - =updinfoAnd only displaying upto the password in the above URL (IE :
          Code: [Select]
          http://IP/admin.cgi?pass=password)

          WIll it not handle the '&' sign? Is there something I can do to prevent this?

          Failing that, it does actually perform the way I want it to.

          many thanks for your help...

          Geek-9pm


            Mastermind
          • Geek After Dark
          • Thanked: 1026
            • Gekk9pm bnlog
          • Certifications: List
          • Computer: Specs
          • Experience: Expert
          • OS: Windows 10
          Re: Launch http page/string from DOS/Command Line?
          « Reply #7 on: May 13, 2011, 08:52:25 AM »

          patio

          • Moderator


          • Genius
          • Maud' Dib
          • Thanked: 1769
            • Yes
          • Experience: Beginner
          • OS: Windows 7
          " Anyone who goes to a psychiatrist should have his head examined. "

          omega1

            Topic Starter


            Rookie

            • Experience: Beginner
            • OS: Unknown
            Re: Launch http page/string from DOS/Command Line?
            « Reply #9 on: May 13, 2011, 09:20:49 AM »
            but im so close, there must be a way to finish this? Can anyone confirm that it is hte '&' symbol that is causing the problem? Apart from that it looks like it will work...

            Sidewinder



              Guru

              Thanked: 139
            • Experience: Familiar
            • OS: Windows 10
            Re: Launch http page/string from DOS/Command Line?
            « Reply #10 on: May 13, 2011, 10:26:15 AM »
            Not fair! Your original post showed very specific contents for A and B. Now we find out, well that's not quite true. Batch code does not generally allow for generic solutions and is very tightly tied to the data. In some cases the code will actually try to execute the data instead of process it. This can be helpful at times if you choose to write clever or creative code, but it lowers readability.

            This little snippet does not rise to the level of clever or even creative, but should provide a solution:

            Code: [Select]
            @echo off
            setlocal

            for /f "tokens=* delims=" %%i in (a.txt) do (
              for /f "tokens=* delims=" %%j in (b.txt) do (
                set url="%%i%%j"
              )
            )

            firefox %url%

            As before, you are responsible for any path information.

             8)
            The true sign of intelligence is not knowledge but imagination.

            -- Albert Einstein

            Salmon Trout

            • Guest
            Re: Launch http page/string from DOS/Command Line?
            « Reply #11 on: May 13, 2011, 10:26:38 AM »
            Can anyone confirm that it is hte '&' symbol that is causing the problem?

            Yes I can confirm that.


            omega1

              Topic Starter


              Rookie

              • Experience: Beginner
              • OS: Unknown
              Re: Launch http page/string from DOS/Command Line?
              « Reply #12 on: May 13, 2011, 12:09:04 PM »
              Hi, that works great, I really appreciate your help