Shoutbox

Input for .bat files - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Input for .bat files (/showthread.php?tid=40520)

Input for .bat files by Vilkku on 03-18-2005 at 08:32 PM

Quick queston, I doubt this is possible.
Is it possible to add input and variables for .bat files? Or we can counter it: how can I use command line commands with java?

Example:

code:
Choose a number: x
net send abc1230x Hello

RE: Input for .bat files by segosa on 03-18-2005 at 11:04 PM

I believe %1, %2, etc refers to each word in the commandline parameters of the .bat file.


RE: Input for .bat files by CookieRevised on 03-19-2005 at 12:00 AM

some commands which can be usefull (type them in dos with /? behind them and you'll see the explainations):
    set /?
    shift /?
    if /?
    goto /?
    for /?

It is far too extensive to explain everything you can do with command lines and/or variables in DOS (it is almost a whole programming language on it's own now). Best is to google for a page which explains some stuff and work from there.

EDIT: but I'll make some quick examples anyways:

In all examples:

  • They all can take a number as command line. If a number is given, the prompt will not be executed. eg:

    C:\> example1.bat<enter>
    Choose a number: 1234<enter>
    net send abc1234 Hello

    C:\> example1.bat 5678<enter>
    net send abc5678 Hello

    C:\> _

  • No 'advanced' checking is done on the validity of the numbers; the user can enter letters as well for example.
  • Remove the 'echo' from the line "echo net send" if you actually want the net send command to be executed. 'echo' is added in these examples so you can clearly see what is suppose to be executed. (don't remove "@echo off" though)


First example:

@echo off
if "%1"=="" (
  set /p choice=Choose a number:
) else (
  set choice=%1
)
echo net send abc%choice% Hello
set choice=


Second example:
- shorter example of the first

@echo off
set choice=%1
if "%choice%"=="" set /p choice=Choose a number:
echo net send abc%choice% Hello
set choice=


Third example:
- variant of the second example:
- if user didn't type a number the question is asked again


@echo off
set choice=%1
:CheckNumber
if "%choice%"=="" set /p choice=Choose a number:
if "%choice%"=="" goto CheckNumber
echo net send abc%choice% Hello
set choice=


Fourth example:
- other version of the third example

@echo off
set choice=%1
:CheckNumber
if "%choice%"=="" (
  set /p choice=Choose a number:
  goto CheckNumber
)
echo net send abc%choice% Hello
set choice=


Fifth example:
- the program will quit when enter is pressed without typing a number

@echo off
set choice=%1
if "%choice%"=="" set /p choice=Choose a number:
if not "%choice%"=="" echo net send abc%choice% Hello
set choice=



RE: Input for .bat files by lopardo on 03-19-2005 at 03:09 AM

Really good page about batch files: http://www.robvanderwoude.com/


RE: Input for .bat files by Vilkku on 04-07-2005 at 10:54 AM

Thank you all <3

*I deleted the old post and reposted it with the following message to get you to read this*

Is there any similar thing to Javas x++, so that I could set how many times I could send the message?