Dylan Frost
Dylan Frost

Reputation: 471

Batch file to open server with port

I am trying to write a script to connect to a server on a specific port. I can get the script to open the browser with the server address as long as I don't include the port. If I try to include the port then I get an error saying:

There is no program associated to perform the requested action...

When I exclude the port it attempts to connect to the server in the browser, but this won't work without a port. Here's some of my code:

@ECHO off

SET serv=exampleserver.company.com

ECHO Server address is %serv%   

SET /p port=Enter the port number 

ECHO The port is %port%

SET addr=www.%serv%

ECHO Your full address is %addr%:%port%

START %addr%:%port%

PAUSE
EXIT

Upvotes: 0

Views: 2066

Answers (1)

ths
ths

Reputation: 2942

as you can test manually, while start www.stackoverflow.com will work, start stackoverflow.com won't, and neither start www.stackoverflow.com:80. I suspect that the recognition of "www." is a especially encoded exception.
To resolve this, use start http://<server>:<port>.

as an aside, if you surround your start parameter with quotes (required if it has a space or other separator), you need to put (empty) quotes before, like start "" "c:\program files\bla", since the first quoted argument will be interpreted as a window title.

xyz:abc is actually a valid filename under windows, where the second part names an alternate data stream (ADS).

Upvotes: 2

Related Questions