Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/cgi-bin/test.py
blob: 097c4b230db20724ce237a52835910db120df3a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

#!/usr/bin/python

import sys, subprocess
cmd = 'scp test.py admin@schoolserver:~'
print 'execute Popen', cmd
"""
pid = subprocess.Popen(cmd, 
    stdout=subprocess.PIPE, 
    stderr=subprocess.PIPE,
    bufsize = -1, 
    shell=True)

print 'subprocess open'
pid.wait()
print 'done'
(result, err) = pid.communicate()
print result, err

if 'NASTY' in err:
    #we have the known hosts problem
    rmcmd = 'rm /home/tony/.ssh/known_hosts'
    subprocess.call(rmcmd, shell=True)
    #now try again and send answer yes
    pid = subprocess.Popen(cmd, 
        stdout=PIPE, 
        stderr=PIPE, 
        shell=True)
    pid.wait()
    (result,err) = pid.communicate()
    print 'result', result
    print 'err', err
"""
cmd = 'cat - |sftp admin@schoolserver'
try:
    pid = subprocess.Popen(cmd,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        stdin=subprocess.PIPE,
        shell=True)
    (result,err) = pid.communicate('yes\n')
except:
    print 'failed', sys.exc_info()[:2]
    result = ''
    err = ''
finally:
    print 'result', result
    print 'err', err

print 'done'