aspose file tools*
The moose likes Java in General and the fly likes getRuntime().exec() - HELP PLEASE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "getRuntime().exec() - HELP PLEASE" Watch "getRuntime().exec() - HELP PLEASE" New topic
Author

getRuntime().exec() - HELP PLEASE

Arpita
Greenhorn

Joined: Aug 27, 2001
Posts: 1
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

Joined: Aug 17, 2001
Posts: 109
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


Sun Certified Programmer on the Java 2 Platform
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getRuntime().exec() - HELP PLEASE