1
mirror of https://github.com/rapid7/metasploit-framework synced 2024-11-12 11:52:01 +01:00

Added error handling to m_exec function since some commands are not present on all versions of Windows

git-svn-id: file:///home/svn/framework3/trunk@9792 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
Carlos Perez 2010-07-12 13:02:44 +00:00
parent 5b3fa182ba
commit fdc22dabf6

View File

@ -8,7 +8,7 @@
#
# hdm[at]metasploit.com
#
@client = client
opts = Rex::Parser::Arguments.new(
"-h" => [ false,"Help menu." ]
)
@ -40,14 +40,19 @@ end
# Exec a command and return the results
def m_exec(session, cmd)
r = session.sys.process.execute(cmd, nil, {'Hidden' => true, 'Channelized' => true})
b = ""
while(d = r.channel.read)
b << d
begin
r = @client.sys.process.execute(cmd, nil, {'Hidden' => true, 'Channelized' => true})
b = ""
while(d = r.channel.read)
b << d
end
r.channel.close
r.close
b
rescue ::Exception => e
print_error("Failed to run command #{cmd}")
print_error("Error: #{e.class} #{e}")
end
r.channel.close
r.close
b
end