locked
Problem in executing powershell using JAVA RRS feed

  • Question

  • Hi,

    I have simple powershell script as below :

    # Filename: Hello.ps1

    Write-Host
    Write-Host 'Hello World!'
    Write-Host "Good-bye World! `n"

    # end of script

     

    I wish to run this script via JAVA by the below JAVA code -

     

    import java.io.*;

     

    public class PsJava {

     

          public static void main(String[] args) throws IOException{

               

            Runtime runtime = Runtime.getRuntime();

            String cmds = (String) "cmd /C powershell C:/Documents and Settings/vvenkata/My         Documents/Hello.ps1";

     

     

            Process proc = runtime.exec(cmds);

     

     

            proc.getOutputStream().close();

            InputStream inputstream = proc.getInputStream();

                InputStreamReader inputstreamreader = new InputStreamReader(inputstream);

                BufferedReader bufferedreader = new BufferedReader(inputstreamreader);

            String line;

            while ((line = bufferedreader.readLine()) != null) {

                System.out.println(line);          

          }

     

    }

    }

     

    Why is that I am not able to see any print statements in Eclipse from Hello.ps1? Can anyone help me out in this..

     

    Thanks,

    Vamsi

    Thursday, July 15, 2010 10:25 PM

Answers

  • Hi,

     

    As the issue is due to JAVA coding in executing Windows PowerShell, I kindly recommend you to contact JAVA for support and post in Windows PowerShell Discussion Group for a better assistance. Meanwhile, you could search in Windows PowerShell Blog for information.

     

    Best Regards

    Dale


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
    • Marked as answer by Dale Qiao Wednesday, July 21, 2010 6:49 AM
    Monday, July 19, 2010 5:10 AM