beermequik
asked on
Runtime.execute("Some batch file")
To conform with Sarbanes-Oxley, I am writing a Java program that will allow a user to login to an intranet site and request a password for an "Emergeny login Profile" on an AS400.
My code verifies that the user is authorized to access this profile and then changes the password for that profile and divulges it to the user.
I am having problems when executing the call that changes the password.
//code snippet (in a servlet)
...
...
...
// generate a random 10 charcter password (first must be alphabetic, rest are alphameric)
profile.switchPassword(use rBean.getU serName(), Integer.parseInt(duration) , reason);
// Now actually switch it on the AS400
Runtime run = Runtime.getRuntime();
String[] commandLine = {"C:\\WINNT\\rmtcmd.exe"," chgusrprf" , profile.getProfileName(), profile.getPassword()};
Process proc = run.exec(commandLine);
int exitCode = proc.waitFor();
if (exitCode != 0){
throw new Exception("Error changing password on AS/400. Error Code: " + exitCode);
}
...
...
...
--Batch file contents..
RMTCMD chgusrprf %1 %2
-- End of Batch File Contents
I have the connection properties set up in AS400 Operations to use a default user and prompt for password when necessary.
I have the same user set up on the windows server with the same password.
When I execute the commandline from either the RUN prompt in window, or in a DOS environment, it works fine.
When called via the java code, the password gets changed successfully, but the code seems to hang at the call to proc.waitFor().
After reading the documentation,it is my understanding that the servlet thread waits until the call to the batch file finishes. The batch file obviously finished because the password got changed.
I need a way of knowing that the call "RMTCMD chgusrprf profilename password" was successful before I divulge the password to the user.
If more info is needed, please let me know.
Any help would be appreciated.
Thanks
My code verifies that the user is authorized to access this profile and then changes the password for that profile and divulges it to the user.
I am having problems when executing the call that changes the password.
//code snippet (in a servlet)
...
...
...
// generate a random 10 charcter password (first must be alphabetic, rest are alphameric)
profile.switchPassword(use
// Now actually switch it on the AS400
Runtime run = Runtime.getRuntime();
String[] commandLine = {"C:\\WINNT\\rmtcmd.exe","
Process proc = run.exec(commandLine);
int exitCode = proc.waitFor();
if (exitCode != 0){
throw new Exception("Error changing password on AS/400. Error Code: " + exitCode);
}
...
...
...
--Batch file contents..
RMTCMD chgusrprf %1 %2
-- End of Batch File Contents
I have the connection properties set up in AS400 Operations to use a default user and prompt for password when necessary.
I have the same user set up on the windows server with the same password.
When I execute the commandline from either the RUN prompt in window, or in a DOS environment, it works fine.
When called via the java code, the password gets changed successfully, but the code seems to hang at the call to proc.waitFor().
After reading the documentation,it is my understanding that the servlet thread waits until the call to the batch file finishes. The batch file obviously finished because the password got changed.
I need a way of knowing that the call "RMTCMD chgusrprf profilename password" was successful before I divulge the password to the user.
If more info is needed, please let me know.
Any help would be appreciated.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
another possible idea is to create a CL with this command in it (CHGUSRPRF) passing in the necessary parms. After the statement has been executed, send back a return value to your program. Enter the CL as a stored procedure.
ASKER
That did it! Thanks
I was trying to read the output streams at one time, but was unsuccessful (I never used Streams outside of files)
Thanks for the code snippet too.
I was trying to read the output streams at one time, but was unsuccessful (I never used Streams outside of files)
Thanks for the code snippet too.
Glad I could help :-)
Good luck with it!!
Tim
Good luck with it!!
Tim