I am stuck in a scenario where I need to run a jar file which decrypts an encrypted file on regular interval from a particular directory on a windows server. Anyone can help in powershell which executes the jar file ?
I use the following command to run the jar file using command prompt and it works fine on local machine.
java -cp PGPDecrypt.jar pgpDecryptPackage.PGPDecrypt C:\Users\anirudgu\Desktop\abcd\TestFile.pgp C:\Users\anirudgu\Desktop\abcd\anirudguprivatekey.asc C:\Users\anirudgu\Desktop\abcd\outputfile.txt Passcode
This jar takes 4 parameters as input
File Path of encrypted file
File path of private key
File path where we need to put the output i.e. decrypted file
The passphase
The output of the is basically a string : File decrypted successfully and placed at location : C:\Users\anirudgu\Desktop\abcd\outputfile.txt
Can someone please suggest on the powershell side ?
This should work in powershell:
cmd.exe /c 'java -cp PGPDecrypt.jar pgpDecryptPackage.PGPDecrypt C:\Users\anirudgu\Desktop\abcd\TestFile.pgp C:\Users\anirudgu\Desktop\abcd\anirudguprivatekey.asc C:\Users\anirudgu\Desktop\abcd\outputfile.txt Passcode'
The '/C' argument, executes a cmd session and then terminates.
For creating a scheduled script:
https://community.spiceworks.com/how_to/17736-run-powershell-scripts-from-task-scheduler
Related
How can I execute SQL*PLUS to execute a script. The script will generate a file, and I would like to move that generated file to a directory.
This is how the process is.
In run.sh file, I give values to parameters of a bash script
./run.sh <schema_name> <user_name> <password> <environment>
These values are passed to the sql.java:
first java goes to the following directory.
./system_scripts
There java starts SQL* PLUS and executes a script (gen.ddl) by using this command:
sqlplus <user_name>/<password>#<environment> gen.ddl
This will create a result file: result.ddl
Move (not copy) that result.ddl file to. Overwrite the previous file if any:
./schema/<schema_name>/scripts
print a message
job done
and done.
How can I do so?
thanks in advance :-)
I am using a .jar file, but unfortunatley as a black box, i.e. I do not know what exactly is in there nor how it all works.
I am sending commands to the Mac terminal from a Python script. I enter the following command:
java -jar jarfile.jar req_data /abs_path/to/required/data input path/to_my_/input/file.txt
This does what I need: analyses input using the 'black box' and creates and new file with analysis output. This new file is created in the folder where jarfile.jar is located.
I want to have this file put somewhere else upon creation.
I have tried using the > operator, specifying a path, e.g.:
java -jar jarfile.jar req_data /abs_path/to/required/data input path/to_my_/input/file.txt > /output/path/
this created a file in my desired location, but it was simply the message from Terminal, saying "The operation was carried out successfully" - the analysis results file was created in the same folder as before.
I tried %*> too, but it threw an error.
As a poor workaround I now have a function, which retrospectively finds and moves all the newly created files (analysis output) to my desired folder.
Is there a way to control the output files with the command line within the original command? Or is it something that is specified somewhere in my jar file? My problem is that editing it is not allowed.
I'm new to python. However, I may suggest to try few things, if they can work for you. Apology me, if does not work! I believe that you have already done the following step:
import subprocess
subprocess.call(['java', '-jar', 'Blender.jar'])
Like, if you have a properly configured jar path, then can run jar directly.
Secondly, look at the cwd parameter (is used for executable). Include a cwd param as x
def run_command(command, **x):
with subprocess.Popen(command,...., **x) as p:
for run_command specify the path of either the working directory (possibly it should be) or the full system path. I'm not sure, just try both.
for outputline in run_command(r'java -jar jarfilepath', cwd=r'workingdirpath', universal_newlines=True):
print(outputline, end='')
Alternatively, you can try to run command from the directory in which you wish to store output file. Try: run the popen as
subprocess.Popen(r'directory of running command', cwd=r'workingdir')
where workingdir could be your current directory path.
If it does not work, try without r'. If still does not work, try doubling slash in the path like (C:\\ abc\\def)
I need to run a Java application at windows shutdown. I have Windows 7 and I have tried to do this in 2 ways:
I have created a .bat file containing the following:
javaw -Xmx200m -jar C:\path\to\jar\dl.jar
dl.jar is the application I need to run at shutdown and I added in Local Group Policies->Windows Settings->Scripts(Stratup/Shutdown)->Shutdown->Script Name my batch file, but it doesn't work.
Also I have added in Shutdown Scripts from Local Group Policies at Script Name: C:\Windows\System32\cmd.exe and at Script Parameters the path to my batch file, it doesn't work in this way either
If I run the .bat file from command promt it works. Does anyone have any idea how to make this work?
I'm trying to create a small Java program that allows you to ask it to open an .exe file in a java window I created.
Here's a small example of what I want
User: Open chrome
Program: starts looking for a file called chrome.exe in C:/ and opens it
And that for any .exe file.
Is there any way to achieve this in Java?
Thanks!
exec(String command, String[] envp, File dir)
Executes the specified string command in a separate process with the specified environment and working directory.
command is the location of the .exe
envp can be null
dir is the directory of your .exe
With respect to your question it should be...
Runtime.getRuntime().exec("c:\\program files\\chrome\\chrome.exe", null, new File("c:\\program files\\chrome");
Process p = Runtime.getRuntime().exec("cmd /c start "+file.getAbsolutePath());
how to run the exe file
and to find files(search) have a read at Java: Find .txt files in specified folder
From a long time i am struggling for with this program. I am having a shell script which accepts parameters as version number and path for the files. then that script creates Zip file with the name of version number congaing all file files to the folder.
I have installed Cygwin on following path D:/cygwin. I am coping required files to same location where cygwin is installed D:\cygwin\bin
Command
D:/cygwin/bin/bash -c '/bin/test/app.sh 04.10 D:\cygwin\bin\ Test_files
Or Can any one please suggest how to run shell script in java using Cygwin.
Rewriting the Problem:-
When i am trying to run following Command in command prompt it gives error
sh app.sh AK-RD 02.20 D:\cygwin\bin\Test_files
Error:-C:\Documents and Settings\sh app.sh AK-RD 02.20 D:\cygwin\bin\Test_files
/usr/bin/app.sh: line 51: lib/lib.sh: No such file or directory
But if i run the same command at
D:cygwin\bin\Test>sh app.sh AK-RD 02.20 D:\cygwin\bin\Test_files
It works fine. Can any one suggest me how to avoid this kind of errors.
Runtime run = Runtime.getRuntime();
Process p = run.exec("D:/cygwin/bin/bash -c \'/bin/test/app.sh 04.10 D:\cygwin\bin\ Test_files");
p.waitFor();