user1067305
user1067305

Reputation: 3481

When calling a browser from Windows command line How can I get it to accept URL parameters

I'm launching a browser (eg firefox) from the command line along with the desired url. (Ultimately I'll be passing it from perl backticks)) But the url has a bunch of parameters which the command processor keeps trying to interpret as executables. How can I get it to just pass them along with the URL? To wit, the command is:

\progra~2\mozill~1\firefox.exe https://finance.yahoo.com/quote/TLT/history?period1=1400828400&period2=1463986800&interval=1mo&filter=history&frequency=1mo

(That URL works just fine if I paste it into the address box of a browser.)

The command line says:

'period2', and 'interval' are not recognized as internal or external commands, operable programs or batch files.

(Why didn't it complain about the other parameter names? Is there a list of "approved parameters" somewhere? )

and it calls the browser with the parameters deleted.

If I enclose everything after the question mark in quotes, the command processor ignores them, and they don't appear in the browser's address box.

Is there some way I can get the command processor to just pass the parameters to the browser? Or else add the parameters to the "approved" if such a thing exists?

Upvotes: 1

Views: 1204

Answers (1)

user7818749
user7818749

Reputation:

Ok so let's see if I can explain how this works.

You click on run and enter \progra~2\mozill~1\firefox.exe https://finance.yahoo.com/quote/TLT/history?period1=1400828400&period2=1463986800&interval=1mo&filter=history&frequency=1mo and click ok. What happens is your browser opens and you have exactly what you want.

Now you take the same and paste it into a cmd line and now it is not working.

The reason is because you are using a specific shell, in this case cmd.exe to call an outside program. The problem is that special characters are recognised by the cmd shell as paramters to use. For instance if you do:

ping localhost & ping 127.0.0.1

cmd.exe sees the & as a function. It means run ping localhost and then ping 127.0.0.1

So when anything inside the cmd shell is a cmd function as well, but we do not want to use it as such and instead send it to external, then we need to enclose it in double quotes. So to prove this we take the same command and give it some double quotes:

ping "localhost & ping 127.0.0.1"

Now we get a different result, because the shell saw that we wanted to ping localhost & ping 127.0.0.1 as a value.

Double quotes is basically a function we use to send everything inside the quotes, to the external program.

so in your case, you want to call the program, and send everything inside the quotes to the program like this:

\progra~2\mozill~1\firefox.exe "https://finance.yahoo.com/quote/TLT/history?period1=1400828400&period2=1463986800&interval=1mo&filter=history&frequency=1mo"

As a side note. Sometimes, although very seldom, you need to use double, double quotes. This is when you might call a shell, within a shell and send a string. The first shell receives the string and removes the first quotes, when trying to send to the external program then, no quotes exist and it fails to execute. When using double Double quotes, it sends the string with quotes to the second shell and that shell then handles it from there. Let me know if you want an example of that, not that it is relevant here.

Upvotes: 2

Related Questions