2014-06-22 5 views
1

Je veux exécuter un script PowerShell à partir de Linux en utilisant JAVA.JAVA Exécute un script PowerShell à partir de Linux

Le script powershell est dans le système Windows. Je dois l'appeler à partir du système Linux en utilisant java bu en passant 2 arguments.

est-ce possible?

grâce

+0

je veux exécuter un script Powershell à distance de linux en utilisant JAVA. – Biswajit

+0

okay ... upvote pour répondre à votre question. mais pourquoi? – Thufir

Répondre

0

obtenu la solution ...

  1. 1er télécharger le FreeSSHD http://www.freesshd.com/?ctt=download dans vos fenêtres (serveur). Assurez-vous de l'exécuter en tant qu'administrateur.

    pour l'installation FreeSSHD suivez cette URL http://www.techrepublic.com/blog/tr-dojo/set-up-a-free-ssh-server-on-windows-7-with-freesshd/ après l'installation, vous pouvez ssh ce système windows de linux ou en utilisant mastic.

  2. d'exécuter le script PowerShell de linux système Windows à distance en utilisant java

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 = "[email protected]"; 
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(); 
} 
} 

utilisation Ganymed jar SSH-2 http://www.ganymed.ethz.ch/ssh2/

Questions connexes