Changeset 35264 in vbox for trunk/src/VBox/Frontends/VBoxShell/vboxshell.py
- Timestamp:
- Dec 20, 2010 6:57:06 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 69112
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxShell/vboxshell.py
r35262 r35264 1061 1061 return 0 1062 1062 1063 def execInGuest(ctx,console,args,env,user,passwd,tmo ):1063 def execInGuest(ctx,console,args,env,user,passwd,tmo,inputPipe=None,outputPipe=None): 1064 1064 if len(args) < 1: 1065 1065 print "exec in guest needs at least program name" … … 1069 1069 gargs = args 1070 1070 print "executing %s with args %s as %s" %(args[0], gargs, user) 1071 (progress, pid) = guest.executeProcess(args[0], 0, gargs, env, user, passwd, tmo) 1071 flags = 0 1072 if inputPipe is not None: 1073 flags = 1 # set WaitForProcessStartOnly 1074 print args[0] 1075 (progress, pid) = guest.executeProcess(args[0], flags, gargs, env, user, passwd, tmo) 1072 1076 print "executed with pid %d" %(pid) 1073 1077 if pid != 0: 1074 1078 try: 1075 1079 while True: 1080 if inputPipe is not None: 1081 indata = inputPipe(ctx) 1082 if indata is not None: 1083 write = len(indata) 1084 off = 0 1085 while write > 0: 1086 w = guest.setProcessInput(pid, 0, 10*1000, indata[off:]) 1087 off = off + w 1088 write = write - w 1089 else: 1090 # EOF 1091 try: 1092 guest.setProcessInput(pid, 1, 10*1000, " ") 1093 except: 1094 pass 1076 1095 data = guest.getProcessOutput(pid, 0, 10000, 4096) 1077 1096 if data and len(data) > 0: … … 1082 1101 data = guest.getProcessOutput(pid, 0, 0, 4096) 1083 1102 if data and len(data) > 0: 1084 sys.stdout.write(data) 1103 if outputPipe is not None: 1104 outputPipe(ctx,data) 1105 else: 1106 sys.stdout.write(data) 1085 1107 continue 1086 1108 if progress.completed: … … 1155 1177 return 0 1156 1178 1157 def gcatCmd(ctx,args): 1158 if (len(args) < 2): 1159 print "usage: gcat [vmname|uuid] local_file | guestProgram, such as gcat linux /home/nike/.bashrc | sh -c 'cat >'" 1179 def readCmdPipe(ctx,hcmd): 1180 try: 1181 return ctx['process'].communicate()[0] 1182 except: 1183 return None 1184 1185 def gpipeCmd(ctx,args): 1186 if (len(args) < 4): 1187 print "usage: gpipe [vmname|uuid] hostProgram guestProgram, such as gpipe linux '/bin/uname -a' '/bin/sh -c \"/usr/bin/tee; /bin/uname -a\"'" 1160 1188 return 0 1161 1189 mach = argsToMach(ctx,args) 1162 1190 if mach == None: 1163 1191 return 0 1164 gargs = args[2:] 1192 hcmd = args[2] 1193 gcmd = args[3] 1194 (user,passwd) = getCred(ctx) 1195 import subprocess 1196 ctx['process'] = subprocess.Popen(split_no_quotes(hcmd), stdout=subprocess.PIPE) 1197 gargs = split_no_quotes(gcmd) 1165 1198 env = [] 1166 (user,passwd) = getCred(ctx) 1167 gargs.insert(0, lambda ctx,mach,console,args: execInGuest(ctx,console,args,env, user, passwd, 0)) 1199 gargs.insert(0, lambda ctx,mach,console,args: execInGuest(ctx,console,args,env,user,passwd, 10000,lambda ctx:readCmdPipe(ctx, hcmd))) 1168 1200 cmdExistingVm(ctx, mach, 'guestlambda', gargs) 1201 try: 1202 ctx['process'].terminate() 1203 except: 1204 pass 1205 ctx['process'] = None 1169 1206 return 0 1170 1207 … … 3064 3101 'gexec':['Executes program in the guest', gexecCmd, 0], 3065 3102 'gcopy':['Copy file to the guest', gcopyCmd, 0], 3103 'gpipe':['Pipe between host and guest', gpipeCmd, 0], 3066 3104 'alias':['Control aliases', aliasCmd, 0], 3067 3105 'verbose':['Toggle verbosity', verboseCmd, 0],
Note:
See TracChangeset
for help on using the changeset viewer.