• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getRuntime().exec() - HELP PLEASE

 
Arpita
Greenhorn
Posts: 1
  • 0
  • 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;
try
{
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)
{
System.out.println(strLine);
out.write(strLine + "\n");
out.flush();
}
in.close();
out.close();
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);
}
}
}
Thanks,
Arpita.
 
Tom Ben
Ranch Hand
Posts: 109
  • 0
  • 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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic