[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: Why chdir command doesn't work with client.get_transport() ?

charles

2/5/2008 7:39:00 PM


Thank you, Matt, for your valuable advice! I did try using ';' to issue three
commands at once and it works!

However, I have more problems with issuing ClearCase commands, which is what
I am really doing.

Under telnet, I could issue commands one by one, just as typing at the
command prompt. Now I tried to use ';' manually typing two commands at once
on my Solaris command line, such as

ct setview viewName; cd dir_in_clearcase

(ct = cleartool) The second command will not be executed, since the command
prompt changes after the first command. --- I think that it was because
there was a long delay after the first command. (any way out?)

When I used exec_command() to do this in Python, even the first command was
not recognized (error: bad phone number. I used 'man ct' and found that ct
dials a phone number). Even if 'ct' was recognized, the second command would
not be executed. And it is useless to do it in the next exec_command()
function. (Without the first command, one can not cd into a directory in
ClearCase.)

Do you think that paramiko can replace telnet in my application? Thanks.

Charles
2/5


Matthew_WARREN wrote:
>
>
> As other have said, it's because exec_command uses a new session each
> time.
>
> You may get some joy with this, untested
>
> exec_command('cd /some/where; somecommand')
>
> uses the semi-colon to separate multiple commands on one command line.
>
>
> Matt.
>
>
>
>
>
> Internet
> charles_hans@yahoo.com
>
> To
>
> python-list
> Sent by:
> cc
> python-list-bounces+matthew.warren=uk.bnpparibas.com@
> python.org
> Subject
>
> Why chdir command doesn't work with
> 02/02/2008 23:41
> client.get_transport() ?
>
>
>
>
>
>
>
>
>
>
>
>
> I am new to paramiko. I wrote a script to copy files between Solaris and
> XP
> machines as below:
>
> import paramiko
> def exec_command(trans, command):
> chan = trans.open_session()
> chan.exec_command(command)
> stdin = chan.makefile('wb')
> stdout = chan.makefile('rb')
> stderr = chan.makefile_stderr('rb')
> return stdin, stdout, stderr
> def main():
> client = paramiko.SSHClient()
> client.connect(hostname, username=username, password=password)
> trans = client.get_transport()
> dummy_chan = trans.open_session()
> exec_command(trans, 'cd temp')
> stdin, stdout, stderr = exec_command(pwd)
>
>>From the last line I found from stdout that the pwd is not changed. I
> tried
> to type the full path in 'cd', did not help. Other UNIX commands such as
> ls,
> mkdir, cp, rm will work. Only this 'cd' never works. I got stuck here.
>
> Please help. Thanks!
>
> Charles
> 2/2
> --
> View this message in context:
> http://www.nabble.com/Why-chdir-command-doesn%27t-work-with-client.get_transport%28%29---tp15248798p152...
>
> Sent from the Python - python-list mailing list archive at Nabble.com.
>
> --
> http://mail.python.org/mailman/listinfo/p...
>
>
>
> This message and any attachments (the "message") is
> intended solely for the addressees and is confidential.
> If you receive this message in error, please delete it and
> immediately notify the sender. Any use not in accord with
> its purpose, any dissemination or disclosure, either whole
> or partial, is prohibited except formal approval. The internet
> can not guarantee the integrity of this message.
> BNP PARIBAS (and its subsidiaries) shall (will) not
> therefore be liable for the message if modified.
> Do not print this message unless it is necessary,
> consider the environment.
>
> ---------------------------------------------
>
> Ce message et toutes les pieces jointes (ci-apres le
> "message") sont etablis a l'intention exclusive de ses
> destinataires et sont confidentiels. Si vous recevez ce
> message par erreur, merci de le detruire et d'en avertir
> immediatement l'expediteur. Toute utilisation de ce
> message non conforme a sa destination, toute diffusion
> ou toute publication, totale ou partielle, est interdite, sauf
> autorisation expresse. L'internet ne permettant pas
> d'assurer l'integrite de ce message, BNP PARIBAS (et ses
> filiales) decline(nt) toute responsabilite au titre de ce
> message, dans l'hypothese ou il aurait ete modifie.
> N'imprimez ce message que si necessaire,
> pensez a l'environnement.
> --
> http://mail.python.org/mailman/listinfo/p...
>
>

--
View this message in context: http://www.nabble.com/Why-chdir-command-doesn%27t-work-with-client.get_transport%28%29---tp15248798p152...
Sent from the Python - python-list mailing list archive at Nabble.com.

5 Answers

Martin v. Loewis

2/5/2008 8:57:00 PM

0

> Do you think that paramiko can replace telnet in my application? Thanks.

You need to use .invoke_shell(), then send() and recv().

Regards,
Martin

Dennis Lee Bieber

2/6/2008 6:33:00 AM

0

On Tue, 5 Feb 2008 11:39:23 -0800 (PST), Charles_hans
<charles_hans@yahoo.com> declaimed the following in comp.lang.python:


> Under telnet, I could issue commands one by one, just as typing at the
> command prompt. Now I tried to use ';' manually typing two commands at once
> on my Solaris command line, such as
>
> ct setview viewName; cd dir_in_clearcase
>
> (ct = cleartool) The second command will not be executed, since the command
> prompt changes after the first command. --- I think that it was because
> there was a long delay after the first command. (any way out?)
>
Part of the problem is that the "cleartool setview" command /itself/
spawns a new shell interpreter. It would be the same as (assuming one
is running, say, bash) entering "csh" at the prompt. An "exit" command
returns one to the prior shell.

Since the entire command line was being parsed by the outer shell,
the inner shell won't see the CD command.

> When I used exec_command() to do this in Python, even the first command was
> not recognized (error: bad phone number. I used 'man ct' and found that ct
> dials a phone number). Even if 'ct' was recognized, the second command would
>
Which basically demonstrated that the shell started from Python
didn't run the same initialization as your login <G>... Somewhere you
have a symbol definition for "ct" to "cleartool".
--
Wulfraed Dennis Lee Bieber KD6MOG
wlfraed@ix.netcom.com wulfraed@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: web-asst@bestiaria.com)
HTTP://www.bestiaria.com/

Ariadne

10/20/2008 8:58:00 PM

0

On 20 Oct, 21:35, kmc...@shell.vex.net (Kenneth McVay OBC) wrote:
> http://mirellewatch.bl...
> --
> "A better idea:  Russian, Chinese, Indian, Korean, French, and Pali
> nukes melting Israel into the sea." ("Chester Field," Leading
> Revisionist Scholar who appears to have forgotten his name.)

Thank you for the link.

Peace Power

10/25/2008 9:25:00 PM

0

Kenneth McVay OBC, is the director and sole owner of Nizkor,
that according to him, is the largest “Holocaust”
(holo-cash) web site on the internet in Canada.

He has been asked to answer this question hundreds of times:
Why should the whole world remember the “Holocaust”
(that does not include the tens of millions who died in
WWII that were not Jewish) when the same people
who suffered this… later do this…?

http://fourthreichisrael.files.wordpress.com/2008/10/dounto...

Mr. McVay claims to have an income of $250.000 a year,
not bad for a guy who was previously working for minimum
wage as a gas station attendant; surely, he is obliged to
answer this most important question.
After all, what is the point in promoting “Lest We Forget”,
when the ongoing Holocaust of the Palestinians that is being
committed by Zionist-Jews in Israel, is not addressed?

http://fourthreichisrael.wordpress.com/2008/10/24/question-for-nizkor-director-kenneth-...

Peace Power

10/25/2008 9:53:00 PM

0

Kenneth McVay OBC, is the director and sole owner of Nizkor,
that according to him, is the largest “Holocaust”
(holo-cash) web site on the internet in Canada.

He has been asked to answer this question hundreds of times:
Why should the whole world remember the “Holocaust”
(that does not include the tens of millions who died in
WWII that were not Jewish) when the same people
who suffered this… later do this…?

http://fourthreichisrael.files.wordpress.com/2008/10/dounto...

Mr. McVay claims to have an income of $250.000 a year,
not bad for a guy who was previously working for minimum
wage as a gas station attendant; surely, he is obliged to
answer this most important question.
After all, what is the point in promoting “Lest We Forget”,
when the ongoing Holocaust of the Palestinians that is being
committed by Zionist-Jews in Israel, is not addressed?

http://fourthreichisrael.wordpress.com/2008/10/24/question-for-nizkor-director-kenneth-...