String cd = "";
String file="E:/Code.java";
cd+="powershell\n";
cd+="$username=\"mail@gmail.com”;\n";
cd+="$password=”pwd”;\n";
cd+="$smtpServer = “smtp.gmail.com”;\n";
cd+="$msg = new-object Net.Mail.MailMessage;\n";
cd+="$smtp = new-object Net.Mail.SmtpClient($smtpServer,587);\n";
cd+="$smtp.Credentials = New-Object System.Net.NetworkCredential(\"mail@gmail.com\", \"password\");\n";
cd+="$smtp.EnableSsl = $true;\n";
cd+="$msg.From = \"mail@gmail\";\n";
cd+="$msg.To.Add(“mail@gmail.com”);\n";
cd+="$msg.Body=”Your message Body”;\n";
cd+="$msg.Subject = “"+System.getProperty("user.name")+"”;\n";
cd+="$file=“"+file+"”;\n";
cd+="$att = new-object Net.Mail.Attachment($file);\n";
cd+="$msg.Attachments.Add($att);\n";
cd+="$smtp.Send($msg);";
String line;
Process p=Runtime.getRuntime().exec(cd);
System.out.println("Standard Error:");
BufferedReader stderr = new BufferedReader(new InputStreamReader(
p.getErrorStream()));
while ((line = stderr.readLine()) != null) {
System.out.println(line);
}
stderr.close();
System.out.println("Done");
Run Code Online (Sandbox Code Playgroud)
输出是:
标准错误:字符串缺少终止符:“。+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException +fullyQualifiedErrorId : TerminatorExpectedAtEndOfString
完毕
| 归档时间: |
|
| 查看次数: |
6027 次 |
| 最近记录: |