1.

Solve : Launch http page/string from DOS/Command Line??

Answer»

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!
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.
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... thanksYou 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.
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.

ThanksYou 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.

You don't need awk or any other 3rd party program. You also do not need to use the start command with the browser.
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...
AWKQuote from: Geek-9pm on May 13, 2011, 08:52:25 AM

AWK

Sigh...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...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.

Quote from: omega1 on May 13, 2011, 09:20:49 AM
Can anyone confirm that it is hte '&' symbol that is causing the problem?

Yes I can confirm that.

Hi, that works great, I really appreciate your help


Discussion

No Comment Found