Reputation: 342
I am using below shell code in linux i want it to make it in Java.I want to call this command in JAVA
mailq | grep -B1 -i temporarily | grep -iv deferred | \
egrep -i 'jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec' | \
awk -F" " '{print $1}' | awk '{print substr($0,10,14)}'
mailq command shows the queued mail messages with there respective Id and there errors . Like in command above i am looking for messages with temporarily disabled message in it and taking the above message where its id is present in **09089 like this checking the month and than printing the last 5 characters of that id
Upvotes: 2
Views: 1251
Reputation: 41132
If I understood correctly, you want to do the same thing that this shell command, but in pure Java, not by running it from Java. One advantage of the port can be portability.
I think you want JavaMail to do the mail access. I am not a specialist of this API, but I used it in a small Processing program to show its usage: Email sketch.
Then you need to filter out the results and to isolate the part you want, which isn't very hard.
Upvotes: 0
Reputation: 12538
String cmd = "mailq | grep -B1 -i temporarily | grep -iv deferred | "
+"egrep -i 'jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec' |"
+ " \'{print $1}\' | awk \'{print substr($0,10,14)}\'";
try
{
ProcessBuilder pb = new ProcessBuilder("bash", "-c", cmd);
Process p = pb.start();
p.destroy();
}
catch (Exception e)
{e.printStackTrace();}
Upvotes: 3
Reputation: 42441
In general this type of issues is handled in java by 'Runtime' class. Here Runtime example java you can find an example of how to do that
The newer approach would be using ProcessBuilder class though
Upvotes: 0
Reputation: 2359
here http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
Upvotes: 3