0

for example i want to run below script from bat file and that working

cd myproject\java myapp.java

but i want change myapp.java by typing
I try to make a bat file mybat.bat that i can typing mayapp.java from cmd
How to do that thanks

Update

I try below but not working

@ECHO OFF
SET /P uname=Please enter name: 
setlocal
CD myproject\java %uname%
%comd%
pause
endlocal
DeLe
  • 2,442
  • 19
  • 88
  • 133
  • [Get user Input in command prompt](http://stackoverflow.com/questions/17524332/get-user-input-in-command-prompt) – 001 Apr 25 '14 at 02:50
  • CD myproject\java %uname% what is this supposed to do? Type cd /?. As written if a user enters fred it will change to a folder relative to the current folder called "myproject\java fred". What is %comd% supposed to do and If you've set it outsidethe program what is it's value. Why do you have echo off thus hiding all attempts by windows to tell you what is wrong. – tony bd Apr 25 '14 at 03:55

2 Answers2

0

You can store the user input in an environment variable using the following command :

set /p env_var=prompt

But to be safer, protect your parent environmenent using :

setlocal
:your commands...
endlocal
luciole75w
  • 1,109
  • 6
  • 12
  • are you sure the comd is well defined in parent environment? and what is the purpose of the CD line? only a dir change or are you trying to run a java app at the same time? btw setlocal has to be called before set /p to be useful but that is not the cause of your problem – luciole75w Apr 25 '14 at 03:51
0

This should change the working directory to a folder on your desktop called myproject and then launch java with what you have typed.

Java may need the full path to the executable if the error message tells you that java is not a valid name.

@ECHO OFF
SET /P uname=Please enter name: 
CD /d "%userprofile%\desktop\myproject"
java %uname%
pause
foxidrive
  • 40,353
  • 10
  • 53
  • 68