I'm trying to make a basic Java IDE in Notepad++, which is easy as long as you don't use packages. But if you need to use the -classpath parameter, everything gets difficult.
I want to use these codes, I think you can get the idea:
NPP EXEC code:
NPP_SAVE
SET_ENV NPP_FULL_CURRENT_PATH=$(FULL_CURRENT_PATH)
SET_ENV NPP_CURRENT_DIRECTORY=$(CURRENT_DIRECTORY)
SET_ENV NPP_NAME_PART=$(NAME_PART)
npp_run cmd /k d:\Users\User\Desktop\script.cmd
script.cmd
SETX CLASSPATH %CD%
set /p deep=Deepness:
:START
if /I %deep% EQU 0 goto END
cd ..
set /a deep=deep-1
goto START
:END
SETX CLASSPATH %CD%
javac -g -cp %CLASSPATH% %NPP_FULL_CURRENT_PATH%
set /p input=Package:
SETX PACKAGE %input%
java -cp %CLASSPATH% %PACKAGE%.%NPP_NAME_PART%
cmd windows
D:\Users\User\Desktop\programozas\java\P05\konyves>SETX CLASSPATH D:\Users\User\Desktop\programozas\java\P05\konyves
SIKERÜLT: A megadott értéket sikerült menteni.
D:\Users\User\Desktop\programozas\java\P05\konyves>set /p deep=Deepness:
Deepness:1
D:\Users\User\Desktop\programozas\java\P05\konyves>if /I 1 EQU 0 goto END
D:\Users\User\Desktop\programozas\java\P05\konyves>cd ..
D:\Users\User\Desktop\programozas\java\P05>set /a deep=deep-1
D:\Users\User\Desktop\programozas\java\P05>goto START
D:\Users\User\Desktop\programozas\java\P05>if /I 0 EQU 0 goto END
D:\Users\User\Desktop\programozas\java\P05>SETX CLASSPATH D:\Users\User\Desktop\programozas\java\P05
SIKERÜLT: A megadott értéket sikerült menteni.
D:\Users\User\Desktop\programozas\java\P05>javac -g -cp NULL D:\Users\User\Desktop\programozas\java\P05\konyves\KonyvProba.java
(SIKERÜLT means SUCCESS, it managed to save the value)
THE PROBLEM
You can see the problem in the last line of the cmd window. -cp NULL
I don't understand why it's NULL, I've set it in the previous line.
These codes seem to work now, but may be unstable:
set CLASSPATH=%CD%
REM Type in the relative path deepness, for
REM example "package xxx.xxx.xxx;" means 3 deepness
REM No package means 0 deepness
set /p deep=Deepness:
set /a DEEP_FINAL=deep
:START
if /I %deep% EQU 0 goto END
cd ..
set /a deep=deep-1
goto START
:END
set CLASSPATH=%CD%
REM Compiling
javac -g -cp %CLASSPATH% %NPP_FULL_CURRENT_PATH%
REM Executing
if /I %DEEP_FINAL% EQU 0 goto NOPATH
REM May include a "cls" here
REM Type in the package name, for example
REM "package java.util;" becomes "java.util"
set /p PACKAGE=Package:
cls
java -cp %CLASSPATH% %PACKAGE%.%NPP_NAME_PART%
goto FINISH
:NOPATH
cls
java -cp %CLASSPATH% %NPP_NAME_PART%
:FINISH
NPPEXEC code:
cd d:
cd $(CURRENT_DIRECTORY)
NPP_SAVE
SET_ENV NPP_FULL_CURRENT_PATH=$(FULL_CURRENT_PATH)
SET_ENV NPP_CURRENT_DIRECTORY=$(CURRENT_DIRECTORY)
SET_ENV NPP_NAME_PART=$(NAME_PART)
npp_run cmd /k d:\Users\User\Desktop\script.cmd
This may be different for you. For example most users use the c: partition for the source files. Very important: you have to run Notepad++ as administrator! I'll test this from now on, and if it keeps working, I'll post it with more relevant tags, since it would be a Java IDE with Notepad++.
SETX does not set the environment variable in the current cmd instance, but for furure cmd instances. You need to execute a set command to set the value in the current instance.
Related
I have this batch code:
IF [%1]==[] GOTO NoParameter
IF NOT [%1]==[] GOTO Parameter
:NoParameter
SET /p "Name= ASM file name (exclude .ASM): "
TASM /ZI %Name%
IF ERRORLEVEL 1 GOTO End
TLINK /v %Name%
IF ERRORLEVEL 1 GOTO End
TD %Name%
GOTO End
:Parameter
TASM /ZI %1
IF ERRORLEVEL 1 GOTO End
TLINK /v %1
IF ERRORLEVEL 1 GOTO End
TD %1
:End
It works great in CMD, but not in DOSBox, where I actually need it. The script is not paused at SET /p, and proceeds to the next commands, with null as the parameter, then stops at TLINK because the given parameter is invalid. If I input a parameter when running the script from DOSBox, the script works perfectly. Any idea how I can get user input like this?
DOSBox doesn't support XP command extensions such as set /p, the developer was against it.
The only way to input a string of characters is to use another utility such as string25 mentioned on that forum.
fun stuff!!
Manager has just bought a humdinger of a utility. It does everything. It even has command line functionality. If you run BugFixer /a the application will automatically scan the entire drive for cooties. If you run the Bugfixer /b it will scan all of your files on the Windows\system 32 directory and if you run Bugfixer /c the program will scan and repair your Registry. Need to write a batch file that will allow your users to avoid that pesky GUI and efficiently run the Bug fixer through the command line, by asking them which option they would like to initialize.
:TOP
ECHO WHICH BUG FIXER DO YOU NEED TO RUN? A=ALL B=SOME c=REPAIR
SET /P = %USERSPEC%
IF "%1"=="A=ALL" GO TO :FIRST
IF "%1"=="A=all" GO TO :FIRST
:FIRST
CHKDSK C:
ECHO CHECKING ALL FILES ARE COMPLETE
IF "%2"=="B=SOME" GO TO :NEXT
IF "%2"=="b=some" GO TO :NEXT
:NEXT
CHKDSK /F /R C:\WINDOWS/SYSTEM32
ECHO CHECKING SOME FILES ARE COMPLETE
IF "%3"=="REPAIR" GO TO :LAST
IF "%3"=="repair" GO TO :LAST
:LAST
CHKDSK /c
ECHO REPAIR FILES ARE COMPLETED
Like I said fun stuff. Anyone wanna help?
Next script logic could become helpful:
#echo OFF >NUL
setlocal enableextensions
:TOP
echo(
set "USERSPEC="
set /P "USERSPEC=Which bug fixer do you need to run? A=all B=some C=repair? "
if /I "%USERSPEC%"=="A" goto :FIRST
if /I "%USERSPEC%"=="B" goto :NEXT
if /I "%USERSPEC%"=="C" goto :LAST
echo NO CHECK CHOOSEN, BATCH ENDS
goto :ENDSCRIPT
:FIRST
chkdsk C:
echo CHECKING ALL FILES ARE COMPLETE
goto :TOP
:NEXT
chkdsk /F /R C:\WINDOWS/SYSTEM32
echo CHECKING SOME FILES ARE COMPLETE
goto :TOP
:LAST
chkdsk /c
echo REPAIR FILES ARE COMPLETED
goto :TOP
:ENDSCRIPT
endlocal
goto :eof
However, running it:
==>30019117.bat
Which bug fixer do you need to run? A=all B=some C=repair? a
Access Denied as you do not have sufficient privileges.
You have to invoke this utility running in elevated mode.
CHECKING ALL FILES ARE COMPLETE
Which bug fixer do you need to run? A=all B=some C=repair?
NO CHECK CHOOSEN, BATCH ENDS
==>
Resources (advised reading):
An A-Z Index of the Windows CMD command line (command reference)
Windows CMD Shell Command Line Syntax (additional particularities)
Script resources for IT professionals (a huge Script repository)
I'm trying to set the contents of a text file (it contains a single line of text) to a variable. To do this, I'm utilizing "set /p myvariable=
SetLocal EnableExtensions EnableDelayedExpansion
Set RegExist=No
Set RegUnins=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
Reg Query "%RegUnins%\{########-####-####-####-############}"
If "%errorlevel%"=="0" Set RegExist=Yes
If "%regexist%"=="Yes" (
Reg Query "%RegUnins%\{########-####-####-####-############}" /V "DisplayName" >"%temp%\appnam1.txt"
Find /I "This is the value for 'DisplayName'" "%temp%\appnam1.txt" >"%temp%\appnam2.txt"
More +2 "%temp%\appnam2.txt" >"%temp%\appnam3.txt"
Set /P _appnam=<"%temp%\appnam3.txt"
Set appnam=%_appnam:~24,53%
If "%appnam%"=="This is the value for 'DisplayName'" (
Echo - Current version installed: Performing reinstall...
Start "Reinstall" /B /High /Wait "\\server\installs\reinstall.exe"
) Else (
Echo - Previous version installed: Performing upgrade...
Start "Upgrade" /B /High /Wait "\\server\installs\upgrade.exe"
)
) Else (
Echo - Existing version not found: Performing new install...
Start "Install" /B /High /Wait "\\server\installs\new.install.exe"
)
However, even though the "%temp%\appnam3.txt" file contains the correct text, when I check the variables "%_appnam%" and "%appnam%" at those points in the code, they are blank. Therefore, if the machine does have the initial registry entry, it will always perform the upgrade process instead of the reinstall process. Any suggestions? I don't understand why the "set /p" line isn't working. Thanks in advance.
PLease use delayed expansion.
I tried to reproduce your case below. It seems the variable are set delayed, If you'll try to run you script several times, the values will be set.
#echo off
setlocal enableDelayedExpansion
set regexist=Yes
If "%regexist%"=="Yes" (
Set /P _appnam=<"C:\result.csv"
echo !_appnam!
Set appnam=!_appnam:~24,53!
echo !appnam!
)
I want to have two batch files install.bat and uninstall.bat that are in the same folder as my command-line program program.exe.
I want the install.bat to add the current location of program.exe to the System Path environment variable.
Then I want the uninstall.bat to remove any paths to program.exe from the System Path environment variable.
Any ideas on how to do this?
Perhaps This earlier solution would be of assistance.
A modified file to custom-fit your situation would be
#ECHO OFF
SETLOCAL
SET "batchdir=%~dp0"
SET "batchdir=%batchdir:~0,-1%"
SET "newpath="
:temploop
SET tempfile=%random%%random%%random%
IF EXIST "%temp%\%tempfile%*" GOTO temploop
SET "tempfile=%temp%\%tempfile%"
CALL :showpath >"%tempfile%"
:: This part removes the current directory from the path
FOR /f "delims=" %%p IN ('type "%tempfile%"') DO (
CALL :addsegment "%%p"
)
DEL "%tempfile%"
IF /i "%1"=="/u" (SET "newpath=%newpath:~1%") ELSE (SET "newpath=%batchdir%%newpath%")
CALL :getresp "Apply new PATH=%newpath% [Y/N/Q]?"
IF /i "%response%"=="Y" ECHO SETX PATH "%newpath%"
GOTO :EOF
:addsegment
SET "segment=%~1"
IF /i NOT "%segment%"=="%batchdir%" SET "newpath=%newpath%;%segment%"
GOTO :eof
:getresp
SET "response="
SET /p "response=%~1 "
IF /i "%response%"=="Y" GOTO :eof
IF /i "%response%"=="Q" SET "response="&GOTO :eof
IF /i NOT "%response%"=="N" ECHO Please respond Y N or Q to quit&GOTO getresp
GOTO :eof
:showpath
ECHO(%path:;=&ECHO(%
GOTO :eof
Essentially, the two batches are the same - the only difference is that for the INSTALL version, the directory is added into the path.
For this reason, I've simply desgned it so that thisbatch would install the file, and thisbatch /u would uninstall it.
Naturally, the calling of the routine to get a final OK to change the path is optional.
I don't know which options you require for the setx, so the command is simply ECHOed. You'd need to remove the ECHO from the SETX line to activate the setting of the path variable.
Note also that SETX does not set the target variable in existing or the current CMD instances - only those created in the future.
It's also important to remember that using the uninstall feature in this routine would remove the directory from the path without regard to the requirements of any other software.
So, how I have it done right now, is that it that it calls another bat file to update it, and then that batch file updates, and sets %ERRORLEVEL% to 1. At the start of the original program, it checks if errorlevel is 1, if yes, it goes to the main menu, but right now, it doesn't call the update file, it just goes to the menu. This is my code
Main program
IF %errorlevel% EQU 1 goto begin
call updater.bat
:begin
echo MENU
Updater
set=errorlevel 1
wget (updatelink here)
call mainprogram.bat
Right now, sometimes it works, sometimes it doesn't, which leads me to believe that some command is somehow increasing the errorlevel, but the only code before the errorlevel check is
#echo off
color 0f
cls
set currentver=v0.5.6
(check code)IF %errorlevel% EQU 1 goto begin
https://code.google.com/p/flashcart-helper/source/browse/trunk/0.6/FlashcartHelperRobocopy.bat
Here is what I have right now.
Don't play around with errorlevel. It's an internal variable. At the start of a batch, errorlevel will be 0 because all you've done is set a local variable. This will almost always ( never say never ) succeed. Also, if errorlevel is 1, and I'm reading this correctly you also seem to have an infinite loop? From what I understand of what you've said your batches are like this:
Main
#echo off
color 0f
cls
set currentver=v0.5.6
IF %errorlevel% EQU 1 goto begin
call updater.bat
:begin
echo MENU
Updater
set=errorlevel 1
wget (updatelink here)
call mainprogram.bat
As errorlevel get's overwritten each time you do anything you're asking for trouble. Change %errorlevel% to %error% and it should solve your problems. As it's a local environment variable it should also be passed between batch files. Just be careful not to use error elsewhere.
Here is a solution using Dropbox Public Folders and no wget. It uses PowerShell that in on Win7+ machines.
Update the below https://dl.dropboxusercontent.com/u/12345678/ url with your own.
It auto creates a .conf file for configuration.
Set __deploy_mode to 1 for the file on dropbox so the version file can be updated but the script not accidentally executed.
#ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET time_start=%time%
SET time_choice_wait=20
SET script_ver=1.00
SET script_name=%~n0
SET server_url=https://dl.dropboxusercontent.com/u/12345678/
SET script_name_bat=%~dp0%script_name%.bat
SET script_name_cfg=%~dp0%script_name%.conf
SET script_name_latest_ver=%~dp0%script_name%.latest.ver
ECHO %script_name% v%script_ver%
ECHO %script_ver% > %script_name%.current.ver
IF NOT EXIST "%script_name_cfg%" CALL :SCRIPT_MISSING_CFG
FOR /f "delims=" %%x IN (%script_name%.conf) DO (SET "%%x")
IF %__deploy_mode% EQU 1 GOTO :EOF
IF %auto_update_compare% EQU 1 CALL :SCRIPT_COMPARE_VER
:SCRIPT_MAIN
REM =======================================
REM === EDIT BELOW THIS LINE ==
REM TODO Add main content
ECHO.
ECHO Waiting for content...
REM === EDIT ABOVE THIS LINE ==
REM =======================================
GOTO END
:SCRIPT_MISSING_CFG
ECHO Creating new %script_name%.conf file...
ECHO __deploy_mode=0 > "%script_name_cfg%"
ECHO repository_base_url=%server_url% >> "%script_name_cfg%"
ECHO auto_update_compare=1 >> "%script_name_cfg%"
ECHO auto_update_download=1 >> "%script_name_cfg%"
ECHO Update %script_name%.conf as needed, then save and close to continue.
ECHO Waiting for notepad to close...
NOTEPAD "%script_name_cfg%"
GOTO :EOF
:SCRIPT_COMPARE_VER
ECHO Please wait while script versions are compared...
Powershell -command "& { (New-Object Net.WebClient).DownloadFile('%server_url%%script_name%.current.ver', '%script_name_latest_ver%') }"
IF NOT EXIST "%script_name_latest_ver%" GOTO END
SET /p script_latest_ver= < "%script_name_latest_ver%"
IF %script_ver% EQU %script_latest_ver% CALL :SCRIPT_COMPARE_VER_SAME
IF %script_ver% NEQ %script_latest_ver% CALL :SCRIPT_COMPARE_VER_DIFF
GOTO :EOF
:SCRIPT_COMPARE_VER_SAME
ECHO Versions are both %script_name% v%script_ver%
GOTO :EOF
:SCRIPT_COMPARE_VER_DIFF
ECHO Current Version:%script_ver% ^| Server Version:%script_latest_ver%
IF %auto_update_download% EQU 1 GOTO SCRIPT_DOWNLOAD_SCRIPT
ECHO.
ECHO Would you like to download the latest %script_name% v%script_latest_ver%?
ECHO Defaulting to N in %time_choice_wait% seconds...
CHOICE /C YN /T %time_choice_wait% /D N
IF ERRORLEVEL 2 GOTO SCRIPT_DOWNLOAD_NOTHING
IF ERRORLEVEL 1 GOTO SCRIPT_DOWNLOAD_SCRIPT
IF ERRORLEVEL 0 GOTO SCRIPT_DOWNLOAD_NOTHING
:SCRIPT_DOWNLOAD_SCRIPT
ECHO Please wait while script downloads...
Powershell -command "& { (New-Object Net.WebClient).DownloadFile('%server_url%%script_name%.bat', '%script_name_bat%') }"
ECHO Script Updated to v%script_latest_ver%^^!
REM User must exit script. Current batch is stale.
GOTO :END
:SCRIPT_DOWNLOAD_NOTHING
GOTO :EOF
:END
SET time_end=%time%
ECHO.
ECHO Script started:%time_start%
ECHO Script ended :%time_end%
:END_AGAIN
pause
ECHO.
ECHO Please close this window
ECHO.
GOTO END_AGAIN
You can do that through these steps:
1.put two files in server,a config file, a higher version bat file which need to update; set last version num. in config file.
2.client bat should be checked update at every startup time. you can read the news version in server config file, then compared to local bat file version. if not equal, so do update, else other wise.
Do you have any problems?