Issue while executing multiple commands

Jan 4, 2013 at 12:51 PM

Hi,

 

I have a requirement where i have to fire module load command before submitting a job.

My Code sequence is as

SshClient client = new SshClient("0.0.0.0", "UN", "PWD");

client.Connect();

SshCommand cmd2 = client.CreateCommand("module list;");
string output1 = cmd2.Execute();

SshCommand cmd = client.CreateCommand("module unload optistruct/optistruct10.0;");
string output = cmd.Execute();

SshCommand cmd1 = client.CreateCommand("module list;");
output1 = cmd1.Execute();

client.Disconnect();

When my second "module list"command is executed the module is still is unloaded.

I googled it around and found

1. Although the connection is opened with the client, but the command to the client is routed through the different channel.

2. Since the channel is being changed everytime, i will not be able to get the desired result.

 

Can anybody help me in using the same channel for the multiple commands.

 

OR i will be left with the only option, where i have to fire all these command in a semi-colon seperated list.

 

Please reply soon

Coordinator
Jan 7, 2013 at 5:34 PM

Hi,,

Unfortunately, I think by design, when SSH closes channel it does not remeber anything from previouse execution.

Also, it seems by design , you cannot execute more then one command per channel.

So it seems you have two option, either execute them using semicolon or use Shell to execute your commands.

 

Thanks,

Oleg