jasypt in cmd: cannot find main class - batch-file

I am using jasypt 1.9.2 in Windows 7 x64 cmd. Here's encrypt.bat content:
ECHO ON
set SCRIPT_NAME=encrypt.bat
set EXECUTABLE_CLASS=org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI
set EXEC_CLASSPATH=.
if "%JASYPT_CLASSPATH%" == "" goto computeclasspath
set EXEC_CLASSPATH=%EXEC_CLASSPATH%;%JASYPT_CLASSPATH%
:computeclasspath
IF "%OS%" == "Windows_NT" setlocal ENABLEDELAYEDEXPANSION
FOR %%c in (%~dp0lib\*.jar) DO set EXEC_CLASSPATH=!EXEC_CLASSPATH!;%%c
IF "%OS%" == "Windows_NT" setlocal DISABLEDELAYEDEXPANSION
set JAVA_EXECUTABLE=java
if "%JAVA_HOME%" == "" goto execute
set JAVA_EXECUTABLE="%JAVA_HOME%\bin\java"
:execute
%JAVA_EXECUTABLE% -classpath %EXEC_CLASSPATH% %EXECUTABLE_CLASS% %SCRIPT_NAME% %*
I got this error(I also tried cd /d [the dir where encrypt.bat is located] and the error persists):
The error message points out that the main class of org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI is no where to be found. I don't understand this. I tried to change JAVA_HOME value in system variables and no luck.

I finally downloaded again the original release and it works. Seems that I messed something up when I was trying to edit the encrypt.bat... I noticed this difference:
With #echo on, I see this output in working version:
C:\Users\myname>FOR %c in (C:\Users\myname\Documents\[APP]\jasypt-1.9.2-dist_new\bin\..\lib\*.jar) DO set EXEC_CLASSPATH=!EXEC_CLASSPATH!;%c
And in my answer I see this:
C:\Users\myname>FOR %c in (C:\Users\myname\Documents\[APP]\jasypt-1.9.2-dist_new\bin\lib\*.jar) DO set EXEC_CLASSPATH=!EXEC_CLASSPATH!;%c
Note the .. before lib.
Also: don't put jaspyt in some path with space! It also cause error, even with quotes.

I also had a same issue when I put unzipped jasypt-1.9.2 folder inside Program Files. You need to move jasypt-1.9.2 folder to C: drive. You should be able to encrypt string without any issues.

I had the same problem with version 1.9.3 . I did the following steps to get it to work:
I cloned the project form its root (https://github.com/jasypt/jasypt.git)
I compiled and packaged the project in /jasypt/ directory using maven (this is the project that is used by the script)
I created the a lib next to bin directory and then I copied the generated jar files into it
then I ran the encrypt.bat again
This way I solved the problem.

call the encrypt.bat/decrypt.bat file instead of the .sh file while you are running from the windows machine.

Related

Opening project in VSCode using batch file

Disclaimer: I read this and this before, but it doesn't work as I want.
Description: I decided to create set of batch files for convenient way to run different projects in VSCode from desktop in one click(double-click). I want close cmd terminal after running a batch file, but terminal remains. I tried:
start code "C:\Users\MyUserName\path\to\my\project\directory"
and
cmd /c start code "C:\Users\MyUserName\path\to\my\project\directory"
It quickly runs command, runs code and opens my project, then, it seems to me, closes terminal and runs a new one in desktop directory.
I found solution with help of DavidPostill. This works fine for me:
start "" cmd /b /c code "C:\Users\MyUserName\path\to\my\project\directory" && exit 0
UPDATE:
There is a more simple way to run VSCode using command line interface:
cd path/to/my/project
code .
If anyone else comes across this in 2022, I found a solution that works great for me.
code "" "C:\path\to\folder\with\project" | exit
Also, below is my batch I made for a quick workspace that:
asks for a folder name, this will also be used as the project name
makes the vscode project
makes 2 text files, one for things I had to look up, and another for answers to my question
makes a png file called work.png that opens with paint for diagrams I might need for thinking through things
Lastly (the part I love the most) it CLOSES the command window once everything is opened!
Hope this helps someone like me who doesn't know everything about batch files!
#echo off &setlocal
set /p "folder=Enter the folder name to be created: "
md "%folder%" ||(pause &goto :eof)
cd %folder%
echo. > Things_I_had_to_look_up.txt
echo. > Answers.txt
dotnet new console
xcopy /s "C:\xPaintFileTemplate" "C:\Users\TBD\Documents\Program Work\%folder%"
start mspaint.exe Work.png
code "" "C:\Users\TBD\Documents\Program Work\%folder%" | exit
Rem not needed but to be safe
exit
The C:\xPaintFileTemplate is a folder in my C drive that contains only a png file named Work.png. The png file is blank, and sized to what I want mspaint to open with. If there are more files in that folder, it will copy all of them, so be careful with xcopy!
The Rem is a comment, saying the exit command doesn't seem to be required but I added it in anyways as I believe it is good practice.
Try using: start cmd /C code . :0 It should be able to close the cmd terminal. At least that worked for me on my Windows 10.
Another version:
start cmd /C code "C:\Users\MyUserName\path\to\my\project\directory" :0
Based on Blake Daugherty's answer, I found the first pair of double quotes seems unnecessary:
code "D:\proj\directory-1" | exit
code "D:\proj\directory-2" | exit
exit
None of the above worked for me; at worst one of the left-over CMD's needed its close button clicking three times before it would go away.
I tried the URL method and this worked just as I wanted: VSCode opened, and the cmd window went away; my batch file ("VSCode on project.bat") contains just one line:
start vscode://file/C:/path/to/project
or:
start "" "vscode://file/C:/path/to/project"
One line code:
code C:\Users\MyUserName\path\to\my\project\directory pause

Batch How to start a program

I want to create a batch file to launch my executable file after it has made some changes to itself.
My batch file is:
START /D "C:\Users\me\AppData\Roaming\Test\Test.exe"
When I run it though I just get a brief console flash and Test.exe doesn't start up.
I've verified the EXE is there in the directory.
I've launched the exe manually to verify it is working as well.
My batch file resides in
C:\Users\admin\AppData\Roaming\run.bat"
There are two issues:
The /D option solely defines the starting or working directory, but not the program to execute.
The start command considers the first quoted argument as the title of the new window. To avoid confusion with other arguments, always provide a window title (that may also be empty).
There are two solutions, which are actually not exactly equivalent:
Remove the /D option, so the current working directory is used:
start "" "C:\Users\me\AppData\Roaming\Test\Test.exe"
Keep the /D option and explicitly provide the new working directory to be used:
start "" /D "C:\Users\me\AppData\Roaming\Test" "Test.exe"
try changing to this
start /d "C:\Users\me\AppData\Roaming\Test" Test.exe
You will see the console flash and your program should startup.
Update
Thanks for #SomethingDark 's suggestion to use the following code.
start "" C:\Users\me\AppData\Roaming\Test\Test.exe
However, the above code will not work if your filename contains space.
Try with the following command.Add it to your batch script.Notice that you have to add double quotes after start keyword if there is/are whitespaces in the path string.
start "" "C:\Users\me\AppData\Roaming\Test\Test.exe"
Enclose any directory names which are longer than one-word into quotation marks. So the following path:
start C:\Program Files\MySQL\MySQL Workbench 8.0 CE\MySQL.exe
Should become something like this:
start C:\"Program Files"\MySQL\"MySQL Workbench 8.0 CE"\MySQL.exe

Unable to start .bat script under Windows 7

This is strange: in general, .bat scripts work fine on this machine. So the PATH variable is fine.
However, I have one script that creates the error message
--> 'C:\Windows\system32\cmd.exe\' is not recognized as an internal ....
Here is the one-line script:
--> #echo %1 | "C:\Program Files\putty\PSFTP.exe" -pw xxx User#Host
This script is working fine on two other Windows 7 machines, just not on mine.
Any ideas what to check?
Is it possible you are using a 64bit version of Windows?. The path may need to be set to point to "C:\Program Files (x86)\Putty"
Actually, the problem had nothing to do with the specific command. Even a
dir | dir
from the command line threw the same error.
I did find the solution here:
https://superuser.com/questions/557387/pipe-not-working-in-cmd-exe-on-windows-7
Problem was the environment variable ComSpec; somehow it had a bad character in the field. I removed that darn back-slash and all is fine.
Thanks for looking at my problem.

How to set a PATH to a batch file in windows

In windows, I have two .bat files, say dir_a/a.bat, and dir_b/b.bat.
What I want is that after executing a.bat, I will be able to call b.bat. My approach now is to set a PATH to dir_b, so in a terminal that executed a.bat, I can just call b.bat and will be able to execute b.bat. Yet putting "set PATH=dir_b;%PATH%" in a.bat is not working. What did I do wrong?
For the case that you're dealing with a relative path:
You might notice that:
set path=%path%;"\..\..\..\vc98\bin\"
will ^^ NOT work ^^ !
So do it like this:
pushd "..\..\..\vc98\bin\"
path %cd%; %path%
popd
...and of course a
set path=%path%;%cd%
between the pushd and popd will also do the trick
Well for also have a look here:
https://stackoverflow.com/a/6595206/3135511
...
call :setAbsPath ABS_PATH ..\
...
^-To see to do it via the self made subfunction 'setAbsPath'
-> or instead of call you may also use For - details in the other thread
And just a small side note for those who might also like to run Microsoft Visual C++ 6.0(anno 1998) > without install it...
... and wonder where's that f*** 'standard' include ?!
There are about 17 file in \vc98\include\ that have been manually chopped 8 + 3 chars. Like:
algrithm -> algorithm
strstrem -> strstream
xception -> exception
So be aware and creative about that !
You must include the absolute path to b.bat file; for example:
set PATH=C:\User A\Folder X\dir_b;%PATH%
I suspect that you have a SETLOCAL in a.bat. ANY environment changes made after a SETLOCAL are backed out when the matching ENDLOCAL (or EOF in the same context) is reached.
Depending on how you are terminating a.bat, you'd need something in the order of ENDLOCAL&set "Path=dir_b;%PATH%"&GOTO :EOF which will prepend dir_b to your existing path as you appear to exepect for the duration of that particular CMD session.
Don't use PATH because that conflicts with the Windows Path. Instead you could add the following:
pushd path_to_your_dir_b
Then add popd in an appropriate place

execute an exe without knowing full path

I need to start an application by the name of Acad.exe without knowing its full path. this path is namly decide upon instalation by the person installing the app.
how can i achive this?
It is common for applications to store their install location in the registry, so the preferred way of finding them would be to look up the appropriate place in the registry. That way, you won't accidentally start a different program with the same file name.
Assuming acad.exe is AutoCAD, this page gives the locations you have to look up.
Try this in any language that has an interface to the OLE2 layer:
CreateDispatch("Autocad.Application")
In C++:
::CoInitializeEx(NULL);
::CreateDispatch("AutoCAD.Application");
With a batch script:
Save the following under the name `start_autocad.vbs
set objShell=CreateObject("Autocad.Application")
objShell.Visible = TRUE
run cscript start_autocad.vbs.
If this acad.exe installation follows the Windows convention, the installation process creates a special key in the registry :
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
If acad.exe is defined there with required parameters then it's possible to start it from a batch file with this simple command :
START acad.exe
No need to specify the complete path, Windows will get it from the corresponding AppPath entry.
Assuming it is on the C: drive, you could do:
#echo off
c:
cd \
for /f "delims=" %%a in ('dir /s /b acad.exe') do set exeLcn=%%a
start %exeLcn%
Instead of inventing your own method, you just might reproduce the behavior of CMD.EXE, looking for ACAD.EXE in the %PATH%.
try this as an example to get you started...
:inpath
echo %~$PATH:1
echo %~dp$PATH:1
goto :eof
invoke it this way
call :inpath acad.exe

Resources