• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

getRuntime().exec() - HELP PLEASE  RSS feed

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am reposting this message because I feel like I did not ask the right questions in the previous post.
I am trying to email a file attachment in Java from Unix and am unsuccessful at many tries. Below is my code. I do get the email but without the file attachment.
In the email command I am redirecting the file in as an attachment. I feel that the problem is with "<" .
I get the email message when I execute the java program, however, I do not get the attachment in the email.
Does anyone know if there is any way to attach a file from mailx or uuencode?
Is it possible to use java mail api in a java application program?
Would PipedOutputStream be useful in this?
The mail command that mails the file is in BOLD( mailCmd = "mailx -s here arpita.patel@prudential.com < ap1" Please help.
import java.io.*;
import java.util.*;
public class UnixCmd {
public static void main (String args[])
String line = null;
System.out.println("This application will mail a file using uuencode");
String strCmd = "uuencode ap ap1";
System.out.println("command: " + strCmd);
Process p = Runtime.getRuntime().exec(strCmd);
File inFile = new File("ap");
FileInputStream f = new FileInputStream(inFile);
InputStream is = p.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(is));
File outfile = new File("ap1");
BufferedWriter out = new BufferedWriter(new FileWriter(outfile));

String strLine;
while ((strLine = in.readLine()) != null)
out.write(strLine + "\n");
String mailCmd;
mailCmd = "mailx -s here arpita.patel@prudential.com < ap1";
System.out.println("mailCmd: " + mailCmd);
Process m = Runtime.getRuntime().exec(mailCmd);
catch (IOException e)
System.out.println("ERROR: " + e);
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have used the java mail API in a Unix platform. You just need them to turn on the SMTP services and then use the boxes' name as the smtpHost. There is an Interface in javax.mail.* called Part this will allow you to attach a file. I would use the java mail API I tried what you are doing and it is just much simplier with Java Mail and more controllable.
Sun Certified Programmer on the Java 2 Platform
please buy this thing and then I get a fat cut of the action:
ScroogeXHTML - small and flexible RTF to HTML converter library
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!