JAVA Execute powershell script from linux -



JAVA Execute powershell script from linux -

i want execute powershell script linux using java.

the powershell script in windows system. have phone call linux scheme using java bu passing 2 arguments.

is possible??

thanks

got solution...

1st download freesshd http://www.freesshd.com/?ctt=download in windows(server). create sure run administrator.

for setup freesshd follow url http://www.techrepublic.com/blog/tr-dojo/set-up-a-free-ssh-server-on-windows-7-with-freesshd/ after setup can ssh windows scheme linux or using putty.

to execute powershell script linux remote windows scheme using java

class="lang-java prettyprint-override">package com.sysvana.router.config; import java.io.bufferedreader; import java.io.ioexception; import java.io.inputstream; import java.io.inputstreamreader; import ch.ethz.ssh2.connection; import ch.ethz.ssh2.session; import ch.ethz.ssh2.streamgobbler; public class test { static string hostname = "10.1.10.60"; static string username = "administrator"; static string password = "p@ssw0rd"; public static void main(string[] args) throws ioexception { connection conn = new connection(hostname); conn.connect(); boolean isauthenticated = conn.authenticatewithpassword (username, password); if (isauthenticated == false){ system.out.println("authentication failed"); } system.out.println(isauthenticated); session sess = conn.opensession (); sess.execcommand ("powershell c:/users/administrator/desktop/test.ps1"); inputstream stdout = new streamgobbler (sess.getstdout ()); bufferedreader br = new bufferedreader (new inputstreamreader (stdout)); while (true) { string line = br.readline (); if (line == null) break; system.out.println (line); } system.out.println ("exit code" + sess.getexitstatus ()); sess.close (); conn.close (); } }

use ganymed ssh-2 jar http://www.ganymed.ethz.ch/ssh2/

java linux windows powershell powershell-v2.0

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -