TerminatorExpectedAtEndOfString

TerminatorExpectedAtEndOfString

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");

输出是:

标准错误:
该字符串缺少终止符:“。
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullQualifiedErrorId : TerminatorExpectedAtEndOfString

完毕

最佳答案

用 Notepad++ 打开代码

查看编码类型。

似乎引号是 ASCII 引号。尝试使用反引号符号后跟双引号,例如:

关于java - 在java中执行powershell命令时出现TerminatorExpectedAtEndOfString错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42811830/

10-08 20:38