4
String cd = "";
    String file="E:/Code.java";
    cd+="powershell\n";
    cd+="$username=\"[email protected]”;\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(\"[email protected]\", \"password\");\n";
    cd+="$smtp.EnableSsl = $true;\n";
    cd+="$msg.From = \"mail@gmail\";\n";
    cd+="$msg.To.Add(“[email protected]”);\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");

The output is :


Standard Error: The string is missing the terminator: ". + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

Done

1
  • 2
    and aren't ASCII doublequotes. Use an escaped doublequote `" Commented Mar 15, 2017 at 13:59

1 Answer 1

5

Open the code with Notepad++

See the encoding type.

It seems that the quotes are ASCII quotes. Try using the backtick symbol followed by the double quotes like :

`"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.