Skip to content

Tag: bash

Decrease the number of calls

I have arraylist of filenames (java) and I want to delete these files using rm but it is time consuming can I do batching using xargs or something else which can help to delete files faster. Answer Don’t use rm. Use Java. As others have pointed out, spawning a process is much slower than doing it in your prog…

Passing shell arguments to java

I want to pass input to java in a Bash shell: This is my Java code: The result is: Answer This is more of a shell programming problem. You need to write: This will convert the output of echo to parameters. This will work as along as the output of your program is simple (e.g., a short list of words).

Exit java program to linux command

I’m making a little tool that handles a sort of exotic device, with lots of options to manage it etc. One of them would be to scan for tty ports, find the right one then throw the user to “minicom” with some parameters for example. How can I make java completely exit while running a specific…

How to run async bash command in java?

I’m trying to run an async bash command from a java file and wait for it to finish before I continue the java code execution. At this moment I’ve tried using Callable like so: and I call it like so: Thanks!!! Answer An easier way is to use Java 9+ .onExit(): If you want to block anyway, use .waitF…

Double backslash under Linux bash

In the Linux bash to identify a Windows folder I have to use double backslash for example “java -jar myjar.jar C:\Users\username” while in the Windows command prompt does not need, just “java -jar myjar.jar C:Usersusername”, is it normal? Answer Yes, the backslash is used for newlines …

How to run sed command from java code

I’m probably missing something, but I’m trying to run commandline from a java The code is as following: I’m getting the following error: The fils is exists. I’m doing ll on this file and it is exists. I’m just looking for a way to make it work from java. What am I doing wrong? An…