Skip to content

Commit e07c19a

Browse files
committed
Expose single command execute methods
1 parent 9475ba2 commit e07c19a

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

winrm4j/src/main/java/io/cloudsoft/winrm4j/winrm/WinRmTool.java

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,24 @@ private WinRmTool(String address, String username, String password) {
2525
this.password = password;
2626
}
2727

28+
/**
29+
* Execute a list of Windows Native commands as one command.
30+
* The method translates the list of commands to a single String command with a <code>"\r\n"</code> delimiter and a terminating one.
31+
* @param commands
32+
* @deprecated since 0.2; Use the {@link #executeCommand(String)} instead and transform your commands list explicitly
33+
*/
34+
@Deprecated
2835
public WinRmToolResponse executeScript(List<String> commands) {
29-
return executeScript(joinScript(commands));
36+
return executeCommand(joinScript(commands));
3037
}
3138

32-
public WinRmToolResponse executeScript(String commands) {
39+
/**
40+
* Executes a Native Windows command.
41+
* It is creating a new Shell on the destination host each time it is being called.
42+
* @param command
43+
* @since 0.2
44+
*/
45+
public WinRmToolResponse executeCommand(String command) {
3346
Builder builder = WinRmClient.builder(getEndpointUrl());
3447
if (username != null && password != null) {
3548
builder.credentials(username, password);
@@ -40,7 +53,7 @@ public WinRmToolResponse executeScript(String commands) {
4053
StringWriter err = new StringWriter();
4154

4255
try {
43-
int code = client.command(commands, out, err);
56+
int code = client.command(command, out, err);
4457
return new WinRmToolResponse(out.toString(), err.toString(), code);
4558
} finally {
4659
client.disconnect();
@@ -58,8 +71,25 @@ private String getEndpointUrl() {
5871
}
5972
}
6073

61-
public WinRmToolResponse executePs(List<String> commands) {
62-
return executeScript(compilePs(joinPs(commands)));
74+
/**
75+
* Execute a list of Power Shell commands as one command.
76+
* The method translates the list of commands to a single String command with a <code>"\r\n"</code> delimiter and a terminating one.
77+
* @param commands
78+
* @deprecated since 0.2; Use the {@link #executePsCommand(String)} instead and transform your commands list explicitly
79+
*/
80+
@Deprecated
81+
public WinRmToolResponse executePsScript(List<String> commands) {
82+
return executeCommand(compilePs(joinPs(commands)));
83+
}
84+
85+
/**
86+
* Executes a Power Shell command.
87+
* It is creating a new Shell on the destination host each time it is being called.
88+
* @param psCommand
89+
* @since 0.2
90+
*/
91+
public WinRmToolResponse executePsCommand(String psCommand) {
92+
return executeCommand(compilePs(psCommand));
6393
}
6494

6595
private String compilePs(String psScript) {

0 commit comments

Comments
 (0)