How to get the port number from a scm daemon start command sent in a batch file
I am trying to start a daemon, do some work with it then terminate it on completion I can do start "my name" scm daemon start --port 49000 and then scm daemon stop --port 49000 but cannot redirect the console application like so : - start "my name" scm daemon start 2>%TEMP%\portLoc.txt or start "my name" scm daemon start >%TEMP%\portLoc.txt or about three other variations used to get the port number, I don't want to kill all instances of scm. The number I want is there in the console window, but I can't get at it. I'd like not to hard code the port number to avoid using a port already in use or maybe errors when running the application twice. Any hints? Thanks Richard |
2 answers
It looks like you need to escape the redirection character.
See http://superuser.com/questions/338277/windows-cmd-batch-start-and-output-redirection for some hints and tips. Comments
Richard Good
commented Nov 08 '16, 1:15 p.m.
Did see that, when I add the escape characters, the process fires up for a second then closes down, so no dice. Thanks for the attempt |
Try this:
start /b scm.exe daemon start > myName.log 2>&1 I understand that you will then find out the port number in the file myName.log for the use of "scm daemon stop". If the command works for you, you will not get any new command windows, so the title of the start command "my name" is of no use, and you should use the log file name to identify your daemon. Comments Not enough chars to add this as a comment Thanks, that helps, but I am loathe to mark it the right answer as I still can't get the port as the file is locked by the scm process somehow and stalls the system, delayed expansion **** in batch files can also bite you, powershell is the way ahead, but not for this customer!! Try running something like the following and tell me what I am doing wrong!
echo on
set lscmLoc=C:\Utilities\RTC-With-DesManager\jazz\scmtools\eclipse\lscm.bat
::works but hard codes the port, port could be being used for something else, probably better than kiling everything though
start /b %scmLoc% daemon start > %TEMP%\portLoc.txt 2>&1
cd %TEMP%
set ric
::wait for process to start up
:: List snapshots
:: List components
:: echo Logout...
::kils just one daemon
I have added an answer, but it was intended as a comment. I have tried using exclamation marks around variables, found that notepad is somehow instantiated when I load the file containing the port number using a for loop, nothing seems to allow me to get and process the port numbers, batch files are a little before my time so could be doing something stupid, not sure what, don't usually get stuck on something apparently simple for a couple of hours!! delimiters are said to default to spaces and tabs so I have left that out the parameter I want should be token 2. Also tried running this direct and as a batch file with the requisite number of % signs
Donald Nong
commented Nov 10 '16, 2:51 a.m.
Nothing really "wrong" with it, as you've already narrowed down what's not working. We just need to work around it. Apparently the FOR command opens the file in "rw" mode and it fails. So we just need to open the file in "r" mode, same as you can open the file in notepad. I change this line
FOR /F "tokens=2" %A in ('portLoc.txt') do set ric=%Ato set /P port= < portLoc.txtand it works for me. Note 1: during testing, I need to add some delay (using ping) before the set command to allow the file to be created, otherwise I get blank content. Note 2: The correct syntax for a variable for the FOR command in a batch file is %%variable, instead of %variable. Check the help content for details. |
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.