Saved Bookmarks
| 1. |
Solve : Way to set a string to a command output? |
|
Answer» I'm using Windos Xp professional corporate edition. i would like to know if there is a way to set a string to the output of a given command. Computer name \\C-8FCE127AFE9A2 I would like to be able to set a string to the addresses under "Workstations active on:". One of these: Quote NetbiosSmb (000000000000) Is there a way to do this in a standard dos batch file on windows xp pro? Thanks in advance. I'm not helping anyone called Sauron!! Seriously, I'll post something tomorrow. Which workstation did you want? Are there always 4? Quote from: contrex on October 20, 2007, 05:30:21 PM I'm not helping anyone called Sauron!! Ultimately, I wanted to let the user select from any one of the workstations. There will not always be 4, it depends on how many network adapters will be on the machine. This should illustrate the ideas needed: Quote
Saved as ch-adapt.bat Result of run: Quote
You still have leading spaces in the string, dunno if that will be a problem? Is the whole string desired, or part of it? Quote You still have leading spaces in the string, dunno if that will be a problem? Is the whole string desired, or part of it? First, thanks a lot. I thought it may involve making a separate file to first store the information. I just need the adapter address from the string for example: Quote {2FF4CC67-D07D-4FEB-85FD-860B1254C849} Agains, thanks for your help. I have a few questions since I'm new to batch programming. It looks like essentially that your storing the output of the "net config rdr" in a filed called fout.txt in the temp folder. Then you are sorting through that file looking for the identifying string "NetBT_Tcpip" storing them L, adding to a counter named "Count", then outputing the counter next to the the current string in L. The SECOND part looks like it is doing the same thing but that once the count variable equals the chosen number, then it stores the current string in L in chosen adapter. GREAT, I will now try to see if I can isolate just the numeric values from the output. (1) You don't actually need a separate file. It's just that my PC is not on a LAN so i could not just use the output of the command directly. This is how you could do that (note single quotes) for /f "delims==" %%L in ('net config rdr ^| find " NetBT_Tcpip"') do ( commands ) (2) Do you need just the hex string or do you want the curly brackets ("braces" in America, I believe) as well? If the string eg NetBT_Tcpip_{2FF4CC67-D07D-4FEB-85FD-860B1254C849} (00C0A8C16B59) is always a fixed length, you can just select so many characters from the string (first char is position 0) (with curly brackets) the 38 characters starting at position 20 set address=%chosenadaptor:~20,38% (without curly brackets) the 36 characters starting at position 21 set address=%chosenadaptor:~21,36% Or, parse out the chars in between the curly brackets (they will be the second token) with FOR add these lines to the end of my above batch to see what I mean Quote
Quote Quote It looks like essentially that your storing the output of the "net config rdr" in a filed called fout.txt in the temp folder. Then you are sorting through that file looking for the identifying string "NetBT_Tcpip" storing them L, adding to a counter named "Count", then outputing the counter next to the the current string in L. That is exactly right. You've been a great help, yea, I got the adapter addressed narrowed down using the numeric parameters ~20,38 (yes, I needed the curly brackets). One more question, how do I concatenate strings, for example, once I get the adapter address in a string, I need it appended to another string not in the original output, something like: Quote Test.dll|{2FF4CC67-D07D-4FEB-85FD-860B1254C849} Thanks again. Ultimately, these strings are going to be fed as parameters to another command so the syntax has to be just right. Quote from: Z-Funk on October 21, 2007, 07:36:05 AM You've been a great help, yea, I got the adapter addressed narrowed down using the numeric parameters ~20,38 (yes, I needed the curly brackets). Is that a pipe symbol | that I see after Test.dll? To concatenate strings, just put them one after another including any spaces needed e.g. Othercommand.bat Test.dll|%address% Otherprogram.exe Test.dll | %chosenadaptor:~20,38% can mix literal strings and variables set pet1=cat set pet2=dog echo %pet1% and %pet2% and pony set MENAGERIE=%pet1% and %pet2% and pony |
|