Need to abort ExecuteCommand before it returns

Advertisement

yoav
Joined:
Posts:
2

Need to abort ExecuteCommand before it returns

Hi,

I am using .NET assembly with csharp.

I send command to remote server with ExecuteCommand method.

this command at the remote server does not stop alone but only with CTL C

so in my c sharp code - ExecuteCommand method dose not return and cpu is stuck in this line.

is there any way to ecutes command on the remote server with no waiting to the remote server output?

do you have an idea how can I solve this issue?

thanks alot

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,518
Location:
Prague, Czechia

Re: Need to abort ExecuteCommand before it returns

On a typical *nix server, you can run a command on a background using & operator, to avoid blocking the shell.

E.g.: session.ExecuteCommand("sleep 1000 &").Check();

Reply with quote

yoav
Joined:
Posts:
2

Hi Prikryl.

Thanks for the answer.

I tried to run the command on backround but got an error:

for the code:
CommandExecutionResult cmdExResult;
cmdExResult = curSession.ExecuteCommand("sleep 10000 &");


cmdExResult.outpot is:

"-bash: line 40: syntax error near unexpected token `;'\n-bash: line 40: `sleep 10000 & ; echo \"WinSCP: this is end-of-file:$?\"'"

can you please advise?

Thanks

Reply with quote

martin
Site Admin
martin avatar

True. You have to work it around by using something like:

echo "sleep 1000 &" > /tmp/sleep_on_background.sh ; bash /tmp/sleep_on_background.sh

Reply with quote

Advertisement

You can post new topics in this forum