Saved Bookmarks
| 1. |
Solve : Problem with string input under conditional? |
|
Answer» I am having a problem with reading user string input under a conditional statement set /p select="Select: " Fairly straight forward, what I need it to do when the user selects option 2, for him to enter the channels he wishes to scan. However, the parameter that needs to be entered is of the form "-channel 6" or "-channel 1-5", so I am appending the string "-channel" with the user input in the string %option%. However, for some unknown reason, no input is going into the string option. I've tried other string variables with the same result, when I echo the string I get nothing, the only difference of what I've been doing previously is that this is under a conditional "if" under option 2. What is the problem here? 1. The problem is that the WINDOWS NT command interpreter is somewhat simple minded. Using plain vanilla NT syntax, command scripts (preferred term, but many people still call them "batch files") are parsed just once, at run time. When the command processor reads a line of text, it expands any environment variables present.This means that setting variables inside FOR loops and conditional structures such as yours becomes problematic. The solution came with "delayed variable expansion" in Windows 2000. Enable it thus: (a) Place this statement at the beginning of the command script, or at any rate before the loop or conditional structure:- setlocal enabledelayedexpansion (b) The variables that need delayed expansion have exclamation marks front and back (American: exclamation points) instead of percent signs see this modified code which works... 2. Incidentally, the line "goto scan" within the conditional structure is redundant; if you get to that line, you're going to that label anyway! The label itself doesn't seem to serve any useful purpose - maybe it's a leftover from earlier experiments? Quote
Great, thanks, and also the explanation is appreciated. Another question, if I should start a new thread on this let me know. Is it possible to capture the text displayed in the counsol to a text file?Quote from: Z-Funk on October 21, 2007, 01:41:17 PM Great, thanks, and also the explanation is appreciated. As text The easiest way, if you are running the console window in Windows, is to click the icon at the top left corner of the console window, Once the "control menu" opens, select Edit. From there you can Select All, Mark, or Copy the text you require from the command window into the clipboard. Paste into Notepad. (Once some or all of the window contents are selected, pressing Enter does the same as Copy) As an image(This works with most if not all windows, not just command ones) Press the Right Alt and PrintScreen keys together. The whole command window, including border and title bar, is captured as an image and can be pasted with the edit menu of a graphics app such as Paint. Otherwise, of course you do know about redirection? Lol, thanks, but I know how to do it using windows functions, but I mean in a running batch file. For example, if I use a command with produces counsol output, could I make a script within the batch file to capture the counsol output. The problem I'm having with a particular command "> %temp%\fout.txt" isn't capturing all of the output of the command, so I thought that I could just capture the entire counsol outpout on the window and find what I want from there. Thanks in advance. Quote from: Z-Funk on October 21, 2007, 02:11:55 PM The problem I'm having with a particular command "> %temp%\fout.txt" isn't capturing all of the output of the command Could you describe a bit more fully, i.e. what is the command and what is not being captured? I presume the text file fout.txt differs in some way from the command's console output as seen on screen? (Which is odd) The command or program in question does not produce a set output. It is actually a continuous scan for available networks that it detects, so depending on the signals it recieves some networks popup and then dissappear, the console screen is constantly being updated depending on what data is being received. I want to put the available networks in a text file. The obvious way would just have the ACTUAL program put them in a text file. However, it is not my code, although it is open source, but even if I modified it to do so, once the source is updated by the devs, I would again have to modify it. My goal is just to create a shell around the program to make it easier to work with. In any event, the available networks while not in "fout.txt" is on the console screen. I don't know how "> %temp%\fout.txt" works so I don't know why they are not showing on the text file, but I went to c:\documents and settings\sauron\local settings\temp\fout.txt, and opened the text file and it just has the first line of output and that's it no matter how long I let the program run. Let me know if you need more information. I don't see why you don't tell me the name of this program; there may be some WORKAROUND that can be searched for. The program sounds a bit like certain Unix apps such as iwlist. I take it netsh won't do what you want? Sorry, the program is airodump-ng which is part of the aircrack-ng suite of software. The aircrack-ng suite of software is a native linux application. There is a limited windows version with a GUI, but this version is limited in terms of its full functionality. However, there is a cygwin port of the full aircrack-ng suite, as you know Cygwin is a Linux-like environment for Windows. Although Cygwin is not a way to run native linux apps on Windows, you can rebuild an application from source. This version since it is built primarily from the linux source does not have a GUI and runs from the windows console. I was trying to make a shell script to interact with the suite for easy use. There is such a script on linux, but for various reasons it doesn't interact the same way on the Cygwin environment. In particular, the program in question, "airodump-ng is used for packet capturing of raw 802.11 frames and is particularly suitable for collecting WEP IVs". It should be noted that aircrack is DEVELOPED for penetration testing purposes only. So I'm assuming that there is no way to capture the current screen output to a text file though a series of DOS commands? |
|