logo
Tags down

shadow

Java command through CMD not working in C#.NET


By : Luis Antonio Marquez
Date : September 15 2020, 01:00 PM
To fix the issue you can do I'm trying to run a java command in cmd using C# to get some inputs for my program, the path for Java is set correctly, and I am able to run Java commands in the cmd without any trouble but when I tried it in C#, it's showing " 'java' is not recognized as an internal or external command, operable program or batch file. " as if the path is not set. , This line is your problem:
code :
proc.StartInfo.UseShellExecute = false;


Share : facebook icon twitter icon

Problem with starting OpenOffice service (soffice) from Java (command working in commandline, but not from Java)


By : Eddie
Date : March 29 2020, 07:55 AM
will be helpful for those in need I would like to say how I solved this. I created a sh script that basically run the command of soffice for me.
Then from Java I just run the script, and it works fine, like this:
code :
public void startSOfficeService() throws InterruptedException, IOException {
        //First we need to check if the soffice process is running
        String commands = "pgrep soffice";
        Process process = Runtime.getRuntime().exec(commands);
        //Need to wait for this command to execute
        int code = process.waitFor();

        //If we get anything back from readLine, then we know the process is running
        BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
        if (in.readLine() == null) {
            //Nothing back, then we should execute the process
            process = Runtime.getRuntime().exec("/etc/init.d/soffice.sh");
            code = process.waitFor();
            log.debug("soffice script started");
        } else {
            log.debug("soffice script is already running");
        }

        in.close();
    }
public void killSOfficeProcess() throws IOException {
        if (System.getProperty("os.name").matches(("(?i).*Linux.*"))) {
            Runtime.getRuntime().exec("pkill soffice");
        }
    }

Java Application waits for finishing the java exec command to go on working properly again


By : Mikhail Khaliavsky m
Date : March 29 2020, 07:55 AM
wish of those help I'm trying to call a java.jar(it is working by double click) from a java application.And it is working with that code below.The main problem is that when the called jar start to work (a gui application), ı cannot use the my main(another gui application) application.I think it is waiting the exec command's end. How can I manage to run this 2 application properly? , The issue is with your stream consuming code...
code :
while ((inputStream.read(c1) != -1)) {
    standardOutput.append(c1.toString());
}
System.out.println("Standard Output: " + standardOutput.toString());

int n2;
byte[] c2 = new byte[4096];
StringBuffer standardError = new StringBuffer();
while (errorStream.read(c2) != -1) {
    standardError.append(c2.toString());
}

sed command not working from java


By : espen angvoll
Date : March 29 2020, 07:55 AM
I wish this help you Try that :)
The advantage of this solution , it's more easier to debugging because you have the temporary file !
code :
String lineIndex="21";
String line="2";
String currentBid="102";

File temp = File.createTempFile("temp-sh", ".sh"); 



FileWriter fw = new FileWriter(temp);
fw.write("#!/bin/bash\n");
fw.write("sed -i '"+lineIndex+"s/"+line+"/"+currentBid+"/g' data/jsp/items.xml\n");
fw.close();
System.out.println(". "+temp.getAbsolutePath());
Runtime.getRuntime().exec(". "+temp.getAbsolutePath());

Java: Executing shell command from java code not working


By : Blair
Date : March 29 2020, 07:55 AM
like below fixes the issue As RealSkeptic pointed out, pipe characters (|) are not command arguments; they're interpreted by a shell. And you are calling a command (cut) directly rather than using a shell.
This isn't a direct answer to your question, but you can accomplish your task without any shell commands:
code :
Charset charset = Charset.defaultCharset();
MessageDigest digest = MessageDigest.getInstance("SHA-512");

try (DirectoryStream<Path> dir = Files.newDirectoryStream(
        Paths.get("/online/data/test/output/2Zip"), "brita_ids-*.csv")) {

    for (Path file : dir) {
        Files.lines(file, charset)
            .map(line -> line.split(",")[1])
            .sorted(Collator.getInstance()).distinct()
            .forEach(value -> digest.update(value.getBytes(charset)));
    }
}

byte[] sum = digest.digest();

String outputFile = "/online/data/test/output/file_name.txt";
try (Formatter outputFormatter = new Formatter(outputFile)) {
    for (byte sumByte : sum) {
        outputFormatter.format("%02x", sumByte);
    }
    outputFormatter.format(" *%s%n", outputFile);
}

Why is Java Runtime.exec command working but ProcessBuilder not able to execute the Perforce client command?


By : Ala
Date : March 29 2020, 07:55 AM
Any of those help ProcessBuilder wants you to provide the command name and each argument as separate strings. When you (indirectly) perform
code :
pb.command("p4", "label -d mylabel123");
pb.command("p4", "label", "-d", "mylabel123");
Related Posts Related Posts :
  • Converting a big byte array to a natural in a double variable
  • Convert nested list List<List<Object>> into Set<Object>
  • How can I get a specific attribute value for all the keys contained in a HashMap?
  • Print 2D array with a single for loop
  • Intellij "Warning: The jjs tool is planned to be removed from a future JDK release jjs> what to do"
  • My class is Serializable and i have java.io.NotSerializableException why?
  • How to check if all squares of a chessboard got stepped at least once?
  • Netbeans Swing GUI Builder not working with java-module project and Maven
  • How can I convert a huge Resultset of 10 million records to a list in java?
  • What is the most efficient way in terms of memory and performance to print a formatted date+time every second in Java?
  • How can I achieve Null-safety when calling a method written in Java from Kotlin, which throws an exception?
  • Can I use a variable from java file in a scala file?
  • multiple errors while trying to insert into sqlitedatabase
  • Firebase DataSnapshot.getValue() is null
  • Is there anything like Java's AtomicStampedReference in C++?
  • Getting rid of punctuations in Strings
  • How can I execute a Junit test?
  • Alignment indent
  • Condition checking with .endsWith() statement
  • Java - How to find students with their highest marks writing a method in a Student class?
  • Revert minify enabled and proguard effect on decompiled apk
  • What is the difference between <>() and <DataType>() in Java
  • Java Spring Test Autowired Controller is null error
  • No qualifying bean found for dependency [CountryRepository]: expected at least 1 bean which qualifies as autowire candid
  • How to display all elements of LinkedList?
  • How do I check object null checking inside setter method in java?
  • Application accepts duplicated messages from google Pub/Sub even after acknowledge
  • How to Launch GoogleChrome from Selenium Remote Web Driver without ChromeDriver.exe
  • Get part of document into object from Firebase Firestore
  • Is it possible to put two variable types in List?
  • wiremock is throwing Nullpointer when trying from the mvn clean install but working fine with eclipse JunitTest
  • Java download file using a byte[]
  • How to execute shell command with JSON from java
  • Obtain Kubernetes API key with Java
  • Codenameone issue: What will happen to push notification service in ios app after expiration of Pro Account Subscription
  • Producer-consumer problem - both end up waiting
  • List of all z/OS DD statements in JCL job using JZOS toolkit
  • How to Subtract 30Days, 3 Months & 1 Year In Epoch time from now using java?
  • How to save an ArrayList, a custom adapter (and its data) in Android using JSON?
  • Difference between a global variable and an injected variable?
  • Code is crashing, it is meant to take in a full name e.g. John Cena and output it as JCena)
  • If we add a super() in a parent class constructor, which class will this super() invoke while creating an object of the
  • How to configure Jackson and Spring to render objects differently depending on the URL path and level of nesting
  • Java 8 opposite to filter in stream
  • Calling a `scala.Function1[_root_.scala.Predef.String, scala.Any]` from within Java
  • Memory usages high - Slow application response : Used memory value not decreasing + Free memory value not increasing
  • J-Unit 4 Checking return Type
  • JUnit: How to create a test class with dependency injection via the constructor
  • JSON parse error: Cannot deserialize instance of `` out of START_ARRAY token
  • Spring Boot findById is not working but findAllById works fine
  • Do Java class files know about white space?
  • ROOM Framework crashes an application
  • Lombok and changing generic method
  • How do I extract the title attribute and the text using xpath or css selector?
  • Wildfly in Docker container not starting
  • Spring @Component not able to Autowire
  • Validate to check uploaded file is pdf
  • Array not changing Value java
  • Can you link two entitys with OneToOne relationship without a foreign key?
  • In the given example, what is the logic behind the use of the Random class?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk