[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Multiple calls to channel_request_exec()
[Thread Prev] | [Thread Next]
- Subject: Re: Multiple calls to channel_request_exec()
- From: Aris Adamantiadis <aris@xxxxxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Thu, 25 Feb 2010 10:19:17 +0100
- To: libssh@xxxxxxxxxx
Hi, Indeed, you can execute only one command using channel_request_exec. But you may either -execute several commands -start a scripting language example: channel_request_exec(channel,"cd /tmp; mkdir mytest; cd mytest; touch mytest"); This will be executed as only one shell command. Another solution is // Do NOT put the channel into interactive mode/pty channel_request_shell(channel); channel_write(channel,"cd /tmp ; echo OK"); channel_read(...) channel_write(channel,"mkdir mytest ; echo OK"); ... basicaly that's like a shell script. Do not expect being able to parse the "#" or "$" prompts, it won't work... hope this helps. Aris Mark Hessling a écrit : > I'm looking at libssh to enable the replacement of an existing > application that uses raw sockets to control a telnet session. In future > the connection must be done using ssh. > > I tried modifying examples/exec.c and duplicated the block of code that > calls channel_request_exec() to execute "ps aux" and to read the output. > I simply added a call to channel_request_exec() to execute "ls -l", but > I received an error: "Channel exec request failed". > > Should I be able to with libssh, execute a shell command on the remote > host, read its output and execute another shell command and read its > output? > >>From my reading of the documentation it appears that each call to > channel_request_exec() spawns another shell on the remote server, so if > I wanted to execute the following on the remote server: > "cd tmp" > "./run_my_command" > then the second command would not be executed in the "tmp" directory. > > Does libssh then need a "changedirectory" function similar to the one > that sets environment variables? > > Thanks in advance for your responses. >
Re: Multiple calls to channel_request_exec() | Mark Hessling <mark@xxxxxxxx> |
Multiple calls to channel_request_exec() | Mark Hessling <mark@xxxxxxxx> |