Getting following error on executing sqlldr command.
SQL*Loader-704: Internal error: ulconnect: OCIServerAttach [0]
ORA-12154: TNS:could not resolve the connect identifier specified
Following is the sqlldr cmd :
sqlldr BILLING/'"Bill!ng#123#"'#10.113.242.162:1521/bssstc control=/log/bssuser/CDR/Postpaid_CDR_Log/CTRL_File.ctrl log=/log/bssuser/CDR/Postpaid_CDR_Log/LOG_File.log direct=false silent=header skip_unusable_indexes=true rows=200000 bindsize=20000000 readsize=20000000 ERRORS=25000
Note :- When executing the same through command prompt its getting succes.
Following is the code snipt i tried.
Runtime rt = Runtime.getRuntime();
Process proc = null;
try {
proc = rt.exec(sqlLoaderCommand);
InputStream stderr = proc.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine()) != null){
logger.info(line);
}
int exitVal = proc.waitFor();
logger.info("Process exitValue: " + exitVal);
int returnValue = proc.exitValue();
String str = null;
if (returnValue != 0) {
InputStream in = proc.getInputStream();
InputStreamReader preader = new InputStreamReader(in);
BufferedReader breader = new BufferedReader(preader);
String msg = null;
while ((msg = breader.readLine()) != null) {
logger.info(msg);
str = str + msg;
}
System.out.flush();
preader.close();
breader.close();
in.close();
InputStream inError = proc.getErrorStream();
InputStreamReader preaderError = new InputStreamReader(inError);
BufferedReader breaderError = new BufferedReader(preaderError);
String errorMsg = null;
while ((errorMsg = breaderError.readLine()) != null) {
logger.info("Copy Error: " + errorMsg);
str = str + errorMsg;
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
}
I think error could be in your username - "Bill!ng#123#". Check out the quotes escaping rules in Java. Like:
String str = "BILLING/'\"Bill!ng#123#\"'#10.113.242.162:1521";
1) From command line try to execute tnsping 10.113.242.162
if the tool will return full description you have to set "oracle.net.tns_admin" in java.
System.setProperty("oracle.net.tns_admin", "ORACLE_DIRECTORY/network/admin"); -- put correct path here and execute before your code
2) For test you can try to use full connection description .
instead of 10.113.242.162:1521/bssstc ->
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.113.242.162)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=bssstc))
Related
I call the.py file in a basic java project and it takes about 30 seconds to run.
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) {
Process proc;
String line ="";
BufferedReader in;
try {
proc = Runtime.getRuntime().exec("D:\\anaconda\\python.exe " +
"D:/2017/Python/pythonProject8/main.py " +
"D:\\2017\\Python\\pythonProject8\\flower1.jpg");
proc.waitFor();
in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
while ((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
result:
enter image description here
But this code is skipped when I use spring-boot.
#GetMapping("test")
public String test(){
System.out.println(1);
Process proc;
String line = "";
String result = "";
try {
proc = Runtime.getRuntime().exec("D:\\anaconda\\python.exe " +
"D:/2017/Python/pythonProject8/main.py " +
"D:\\2017\\Python\\pythonProject8\\flower3.jpg");// 执行py文件
proc.waitFor();
BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
while ((line = in.readLine()) != null) {
System.out.println(line);
result += line;
}
in.close();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(2);
return result;
}
result:
enter image description here
I want to know how to run spring-boot properly.
thanks.
If your.py file takes a long time to run then you shouldn't use Process and use ProcessBuilder instead.
public ArrayList<String> getPasswords(String path) throws IOException {
String result = "";
ProcessBuilder processBuilder = new ProcessBuilder("D:\\anaconda\\python.exe ", "D:\\2017\\Python\\pythonProject8\\main.py",path);
//The path here is me.py needs to be passed in
processBuilder.redirectErrorStream(true);
final Process process = processBuilder.start();
final BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
String s = null;
int i = 0;
while ((s = in.readLine()) != null)//This if is I need to ignore some of the output
{
i++;
if (i >6) {
result += s + '\n';
}
}
if (!result.equals("")){
return new ArrayList<String>(Arrays.asList(result.split("\n")));
}
return new ArrayList<String>();
}
You may run an error "DLL load failed while importing XXXX".
Please update the packages required for python.
I have to launch console commands from java to publish to verdaccio.
So it works(pretty bad), but for few packages processes stucks. When I destroy them it returns code 137, witch means not enough memory. I watched in profiler, I have much more free heap, then used.
Maybe it's not because not enough memory.
How to understand why it stucks and how to fix it?
protected String execCommand(List<String> command) throws IOException, NpmAlreadyExistException{
ProcessBuilder pb = new ProcessBuilder(command);
File workingFolder = new File(System.getProperty("user.dir"));
pb.directory(workingFolder);
Process process = pb.start();
try {
boolean finished = process.waitFor(60, TimeUnit.SECONDS);
logger.info("PROC FINISHED: " + finished);
if (!finished) {
process.destroyForcibly();
int exitCode = process.waitFor();
logger.info("PROC EXIT CODE: " + exitCode);
return null;
}
} catch (InterruptedException e) {
logger.info("PROCESS WAS INTERRUPTED!!!");
logger.info(e.getMessage());
return null;
}
logger.info("PROC EXIT CODE: " + process.exitValue());
String s;
BufferedReader stdErr = new BufferedReader(new InputStreamReader(process.getErrorStream()));
StringBuilder err = new StringBuilder();
while ((s = stdErr.readLine()) != null) {
err.append("\n").append(s);
}
stdErr.close();
BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
StringBuilder result = new StringBuilder();
while ((s = stdInput.readLine()) != null) {
result.append("\n").append(s);
}
stdInput.close();
process.destroy();
logger.info(String.format("execCommand response [stdin]: %s", result));
logger.info(String.format("execCommand response [stdErr]: %s", err));
if (err.length() != 0) {
if (err.toString().contains("Update the 'version' field in package.json and try again.")) {
throw new NpmAlreadyExistException("Пакет с таким именем и версией уже существует в репозитории.");
}
}
return result.toString();
}
Thank you!
I am trying to download image from server using CURL. Below is the code I am using.
private void executeCMD(String[] cmd) {
ProcessBuilder process = new ProcessBuilder(cmd);
Process p;
try
{
p = process.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
StringBuilder builder = new StringBuilder();
String line = null;
while ( (line = reader.readLine()) != null) {
builder.append(line);
builder.append(System.getProperty("line.separator"));
}
String result = builder.toString();
System.out.print(result);
}
catch (IOException e)
{ System.out.print("error");
e.printStackTrace();
}
}
CMD is :
I can see the binary output(result) on the log files, but its not downloading as image on local drive.
Hi i am trying to run this command that is passed on to the runExternalProgram. When i ran the command through cmd, it was successful and i was able to receive a message but when i run the java program, there was no error issue but no message was received. How should I go about solving this error?
String Command ="cmd /c start java -classpath C:/Users/admin/Desktop/Smsworkspace/sendmessage/src;C:/Users/admin/Desktop/Smsworkspace/sendmessage/src/plivo-java-3.0.9-jar-with-dependencies.jar sendmessage.SendSMS2 +xxxxx +xxxxx CS";
runExternalProgram
public HashMap runExternalProgram_Windows(String Command) {
String _LOC = "[SB_Utilities: runExternalProgram_Windows]";
System.out.println(_LOC + "1.0");
System.out.println("Command is: "+ Command);
String line;
InputStream stderr = null;
InputStream stdout = null;
HashMap _m = new HashMap();
try {
Process process = Runtime.getRuntime ().exec (Command);
System.out.println("Process is: " + process);
Worker worker = new Worker(process);
System.out.println("Worker is: " + worker);
worker.start();
try {
worker.join(180000);
if (worker.exit == null)
{
throw new Exception();
}
}
catch(Exception ex) {
ex.printStackTrace();
_m.put("LOG_ERROR_EXTERNAL", "180 second time out...check connection");
return _m;
}
finally {
process.destroy();
}
stderr = process.getErrorStream ();
stdout = process.getInputStream ();
String _log_output = null;
// clean up if any output in stdout
BufferedReader brCleanUp = new BufferedReader (new InputStreamReader (stdout));
System.out.println("Outcome is: "+brCleanUp.readLine());
while ((line = brCleanUp.readLine ()) != null) {
if (_log_output==null) {
_log_output = line + "\n";
} else {
_log_output = _log_output + line + "\n";
}
}
brCleanUp.close();
_m.put("LOG_OUTPUT", _log_output);
String _log_error = null;
// clean up if any output in stderr
brCleanUp=new BufferedReader (new InputStreamReader (stderr));
System.out.println("Outcome error is "+brCleanUp.readLine());
while ((line = brCleanUp.readLine ()) != null) {
if (_log_error==null) {
_log_error = line + "\n";
} else {
_log_error = _log_error + line + "\n";
}
}
brCleanUp.close();
_m.put("LOG_ERROR_EXTERNAL", _log_error);
} catch (Exception e) {
e.printStackTrace();
}
return _m;
}
I have been trying to run
C:\Users\Luis\Desktop\RESEARCHGUIPROJECT\ResearchGUI\CHEMKED\CHEMKED_SOLVER.exe
using java or having java use the command prompt to run this executable. Now I believe I was to able to get java to the file but when it runs it the executable gives me ERR IO-21 invalid STATUS specifier for given file.
I have ran the executable from the DOS window and usually when that code is given it means the input file has been specified incorrectly. To give background on the solver what it does is read from a file named solverfilepath.txt and in that file a file directory is given to where the file is located. This file is the solvers input named SOLTMP.txt.
This error only occurs when I run java but doesn't occur when I run it manually from the command window.
I don't know if there might be a way when java is running this program to also have it open the command window to see the executable run in the command prompt.
Any suggestions?
int i = 1;
while(finalTime < 1.0000){
try{
// Execute CHEMKED solver
// Added 07/06/2013 from StackOverFlow
Runtime rt = Runtime.getRuntime();
String[] CHEMKED = {"C:\\Users\\Luis\\Desktop\\RESEARCHGUIPROJECT\\ResearchGUI\\CHEMKED\\CHEMKED_SOLVER.exe"};
Process pr = Runtime.getRuntime().exec(CHEMKED);
BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line=null;
while((line=input.readLine()) != null) {
System.out.println("*****");
System.out.println(line);
}
int exitVal;
exitVal = pr.waitFor();
System.out.println("Exited with error code "+exitVal);
} catch(Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}
try{
inputFile3 = new Scanner(new FileReader("CHEMKED\\SOLTMP.txt"));
}catch(Exception e){
e.printStackTrace(System.out);
}
try{
copyFile = new Formatter(new File("CHEMKED\\output-ring1_"+ i +".txt"));
}catch(Exception ex){
ex.printStackTrace(System.out);
}
//copy SOLTMP content to temporary file
while(inputFile3.hasNextLine()){
fileLine = inputFile3.nextLine();
copyFile.format("%s%n",fileLine);
}
copyFile.close();
inputFile3.close();
// Added 07/05/2013
initialTime+= 0.10;
finalTime+= 0.10;
// Added 07.03
updateFile();
i++;
}
So here is what I have added so far simply similar to what was done on javaWorld. I haven't had the chance to run it yet, but just seeing if I am headed in the right direction.
class StreamGobbler extends Thread
{
InputStream is;
String type;
OutputStream os;
StreamGobbler(InputStream is, String type)
{
this(is, type, null);
}
StreamGobbler(InputStream is, String type, OutputStream redirect)
{
this.is = is;
this.type = type;
this.os = redirect;
}
public void run()
{
try
{
PrintWriter pw = null;
if (os != null)
pw = new PrintWriter(os);
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line=null;
while ( (line = br.readLine()) != null)
{
if (pw != null)
pw.println(line);
System.out.println(type + ">" + line);
}
if (pw != null)
pw.flush();
} catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}
public void chemked(String args[]) {
int i = 1;
while(finalTime < 1.0000) {
if (args.length < 1)
{
System.out.println("USAGE java GoodWinRedirect <outputfile>");
System.exit(1);
}
try{
FileOutputStream fos = new FileOutputStream(args[0]);
String[] CHEMKED = { "C:\\Users\\Luis\\Desktop\\RESEARCHGUIPROJECT\\ResearchGUI\\CHEMKED\\CHEMKED_SOLVER.exe"};
Process pr = Runtime.getRuntime().exec(CHEMKED);
BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
// any error message
StreamGobbler errorGobbler = new
StreamGobbler(pr.getErrorStream(), "ERROR");
// any output
StreamGobbler outputGobbler = new
StreamGobbler(pr.getInputStream(), "OUTPUT", fos);
// start them off
errorGobbler.start();
outputGobbler.start();
String line=null;
while((line=input.readLine()) != null) {
System.out.println("*****");
System.out.println(line);
}
int exitVal;
exitVal = pr.waitFor();
System.out.println("Exited with error code "+exitVal);
fos.flush();
fos.close();
} catch(Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}
try{
inputFile3 = new Scanner(new FileReader("CHEMKED\\SOLTMP.txt"));
}catch(Exception e){
e.printStackTrace(System.out);
}
try{
copyFile = new Formatter(new File("CHEMKED\\output-ring1_"+ i +".txt"));
}catch(Exception ex){
ex.printStackTrace(System.out);
}
//copy SOLTMP content to temporary file
while(inputFile3.hasNextLine()){
fileLine = inputFile3.nextLine();
copyFile.format("%s%n",fileLine);
}
copyFile.close();
inputFile3.close();
// Added 07/05/2013
initialTime+= 0.10;
finalTime+= 0.10;
// Added 07.03
updateFile();
i++;
}
}
Let me know thank you.
SOLUTION:
int i = 1;
while(finalTime < 1.0000) {
try{
FileOutputStream fos = new FileOutputStream("C:\\Users\\Luis\\Desktop\\RESEARCHGUIPROJECT\\ResearchGUI\\CHEMKED\\error" +i+".txt");
String[] CHEMKED = { "C:\\Users\\Luis\\Desktop\\RESEARCHGUIPROJECT\\ResearchGUI\\CHEMKED\\CHEMKED_SOLVER.exe", "SOLTMP.txt"};
//Process pr = Runtime.getRuntime().exec(CHEMKED);
ProcessBuilder builder = new ProcessBuilder(CHEMKED);
builder.directory(new File("C:\\Users\\Luis\\Desktop\\RESEARCHGUIPROJECT\\ResearchGUI\\CHEMKED"));
builder.redirectError();
Process pr = builder.start();
BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
// any error message?
StreamGobbler errorGobbler = new
StreamGobbler(pr.getErrorStream(), "ERROR");
// any output?
StreamGobbler outputGobbler = new
StreamGobbler(pr.getInputStream(), "OUTPUT", fos);
// kick them off
errorGobbler.start();
outputGobbler.start();
int exitVal;
exitVal = pr.waitFor();
System.out.println("Exited with error code "+exitVal);
fos.flush();
fos.close();
} catch(Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}
try{
inputFile3 = new Scanner(new FileReader("CHEMKED\\SOLTMP.txt"));
}catch(Exception e){
e.printStackTrace(System.out);
}
try{
copyFile = new Formatter(new File("CHEMKED\\output-ring1_"+ i +".txt"));
}catch(Exception ex){
ex.printStackTrace(System.out);
}
//copy SOLTMP content to temporary file
while(inputFile3.hasNextLine()){
fileLine = inputFile3.nextLine();
copyFile.format("%s%n",fileLine);
}
copyFile.close();
inputFile3.close();
// Added 07/05/2013
initialTime+= 0.10;
finalTime+= 0.10;
// Added 07.03
updateFile();
i++;
}
}
Again, consider using a ProcessBuilder and setting its working directory to be the same location as your executive file. Something like:
String path = "C:/Users/Luis/Desktop/RESEARCHGUIPROJECT/ResearchGUI/CHEMKED/";
String app = "CHEMKED_SOLVER.exe";
List<String> command = new ArrayList<String>();
// command.add(path);
command.add(app);
ProcessBuilder processBuilder = new ProcessBuilder(command);
processBuilder.directory(new File(path));
processBuilder.redirectError();
Process process = processBuilder.start();
BufferedReader bReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line = "";
while ((line = bReader.readLine()) != null) {
System.out.println(line);
}