Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

getRuntime().exec() - HELP PLEASE

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Morning came much too soon and it brought along a friend named Margarita Hangover, and a tiny ad.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic