Making a .bat file to get input

Vote Down
Score
1
Vote Up
ShadowSilent March 8, 2003 at 08:02:27 Pacific
Specs: 2K, 2.0 512

I need to know how I would make a .bat file that would get input (an IP address) and then make a new file (java policy file). I have no clue how to do this....


Reply ↓  Report •


#1
Vote Down
Score
45
Vote Up
Secret_Doom March 8, 2003 at 12:52:39 Pacific

The following method will work on Windows 2000 and XP:

set INPUT=
set /P INPUT=Type input: %=%
echo Your input was: %INPUT%

If user hits ENTER without typing anything, the variable (in this case, %input%) keeps it value. So, the first line is to reset its value, so that if nothing is entered the variable will have no value at all, instead of some senseless value.

As you can see, that accepts blank inputs. You can make it to don't accept:

:input
set INPUT=
set /P INPUT=Type input: %=%
if "%INPUT%"=="" goto input
echo Your input was: %INPUT%

So, after getting user's input and saving it in a variable, you can use it as you will.

Those samples will fail on DOS and Windows 9x and NT (there are other methods to get user input on such OS's).

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br


Reply ↓  Report •

#2
Vote Down
Score
6
Vote Up
ShadowSilent March 8, 2003 at 19:27:14 Pacific

OK thanks alot but I still have one more problem....

I need to put to together a new file witht he input...

Like is there a way to insert the input into a text file?


Reply ↓  Report •

#3
Vote Down
Score
10
Vote Up
Secret_Doom March 8, 2003 at 20:10:20 Pacific

That's the easy part. After getting user's input into a variable, let's say the %input% variable, just do:

echo %input%>> file.ext

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br


Reply ↓  Report •

#4
Vote Down
Score
1
Vote Up
ShadowSilent March 8, 2003 at 21:11:30 Pacific

You saved me!

Thanks a million


Reply ↓  Report •

Related Posts

#5
Vote Down
Score
2
Vote Up
ShadowSilent March 8, 2003 at 21:15:41 Pacific

Sorry to bother you but is there a way to combine two text files?

Like now that I have the input in the first text file I need to paste the second half in....


Reply ↓  Report •

#6
Vote Down
Score
4
Vote Up
ShadowSilent March 8, 2003 at 23:35:13 Pacific

Scratch the last question my problem now is this:


TYPE part1.txt > C:\j2sdk1.4.1_01\bin\myPolicy
:input
set INPUT=
set /P INPUT=Enter the other computers IP address: %=%
if "%INPUT%"=="" goto input
echo IP entered was: %INPUT%
echo %INPUT% >> C:\j2sdk1.4.1_01\bin\myPolicy
TYPE part2.txt >> C:\j2sdk1.4.1_01\bin\myPolicy

The problem is that There is a return between my INPUT and the part2.txt and that screws up teh entire file... How do I fix this?

The output is this:

grant codeBase "http://www.geocities.com/Jman3ooo/-" {
permission java.net.SocketPermission "localhost:1024-", "accept, connect, listen, resolve";
permission java.net.SocketPermission "192.168.0.1
:1024-", "accept, connect, listen, resolve";
};

but I want this:

grant codeBase "http://www.geocities.com/Jman3ooo/-" {
permission java.net.SocketPermission "localhost:1024-", "accept, connect, listen, resolve";
permission java.net.SocketPermission "192.168.0.1:1024-", "accept, connect, listen, resolve";
};


Reply ↓  Report •

#7
Vote Down
Score
2
Vote Up
JSLover March 10, 2003 at 05:48:05 Pacific

Ok I'm confused by the layout on this board (can't tell where it wraps & where it's a real return in file) but this is what I assume...

[RETURN] is real hard return in file (or where I think they are...if they're wrong post again with return indicators)...since this board messes it up

part1.txt
grant codeBase[RETURN]
"http://www.geocities.com/Jman3ooo/-"[RETURN]
{[RETURN]
permission[RETURN]
java.net.SocketPermission[RETURN]
"localhost:1024-", "accept,[RETURN]
connect, listen, resolve";[RETURN]
permission[RETURN]
java.net.SocketPermission[RETURN]
"[No-return-at-end-of-file]

part2.txt
:1024-", "accept,[RETURN]
connect, listen, resolve";[RETURN]
};[Doesn't-matter-if-there-is-or-not]

Ok instead try...

part1.txt
grant codeBase[RETURN]
"http://www.geocities.com/Jman3ooo/-"[RETURN]
{[RETURN]
permission[RETURN]
java.net.SocketPermission[RETURN]
"localhost:1024-", "accept,[RETURN]
connect, listen, resolve";[RETURN]
permission[RETURN]
java.net.SocketPermission[Return-at-end-of-file-this-time]

...end file sooner.

part2.txt
connect, listen, resolve";[RETURN]
};[Still-don't-matter]

...start file later.

.bat file
TYPE part1.txt > C:\j2sdk1.4.1_01\bin\myPolicy[RETURN]
:input[RETURN]
set INPUT=[RETURN]
set /P INPUT=Enter the other computers IP address: %=%[RETURN]
if "%INPUT%"=="" goto input[RETURN]
echo IP entered was: %INPUT%[RETURN]
echo "%INPUT%:1024-", "accept, >> C:\j2sdk1.4.1_01\bin\myPolicy[RETURN]
TYPE part2.txt >> C:\j2sdk1.4.1_01\bin\myPolicy[RETURN]

...modify output line.


Reply ↓  Report •

Reply to Message Icon Start New Discussion
« Appending Text To Multipl... free more dynamic memory?... »

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.

Ask the Community!
Describe your Problem
Example: Hard Drive Not Detected on My PC