elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Los 10 CVE más críticos (peligrosos) de 2020


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  (SOLUCIONADO) Mostrar el output de la CMD
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: (SOLUCIONADO) Mostrar el output de la CMD  (Leído 2,304 veces)
Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.818



Ver Perfil
(SOLUCIONADO) Mostrar el output de la CMD
« en: 25 Noviembre 2012, 20:05 pm »

Hola,

Tengo una pregunta antes de la verdadera pregunta xD

¿Que control es el más adecuado para mostrar el output de la CMD?  (Estoy usando un richtextbox)

Y bueno, el problema es que no consigo que el texto cambie antes d emostrar el output:
Código
  1. Me.consolebox.Text = "Deleting the attributes of the files..."

Todo lo demás funciona bien, pero no consigo mostrar ese string, se queda el richtextbox vacío hasta que finaliza el búcle...

Código
  1.   Private Function attrib() As Boolean
  2.        Me.consolebox.Text = "Deleting the attributes of the files..."
  3.        Dim attrib_process As New Process()
  4.        Dim attrib_startinfo As New ProcessStartInfo()
  5.        Dim attrib_args As String = videofolder
  6.        attrib_startinfo.FileName = "cmd.exe "
  7.        attrib_startinfo.UseShellExecute = False
  8.        attrib_startinfo.CreateNoWindow = True
  9.        attrib_startinfo.Arguments = "/C PUSHD " & ControlChars.Quote & videofolder & ControlChars.Quote & " & Attrib -A -R -S -H -I /S *.* & attrib +H /S *.ico >nul & attrib +H -R /S *.ini >nul"
  10.        attrib_startinfo.RedirectStandardOutput = True
  11.        attrib_process.EnableRaisingEvents = True
  12.        attrib_process.StartInfo = attrib_startinfo
  13.        attrib_process.Start()
  14.        Dim readerStdOut As IO.StreamReader = attrib_process.StandardOutput
  15.        Do While readerStdOut.EndOfStream = False
  16.            output = output + readerStdOut.ReadLine()
  17.        Loop
  18.        Me.consolebox.Text = "This is the result of the command:" + output
  19.    End Function

¿Y si necesito usar un comando de múltiples líneas como le hago?

por ejemplo:
Código
  1. attrib_startinfo.Arguments = "/C
  2. Echo linea 1 &
  3. (Echo linea2
  4. Echo linea 3)
  5. "


« Última modificación: 25 Noviembre 2012, 22:30 pm por EleKtro H@cker » En línea

Keyen Night


Desconectado Desconectado

Mensajes: 496


Nothing


Ver Perfil
Re: Mostrar el output de la CMD
« Respuesta #1 en: 25 Noviembre 2012, 22:07 pm »

Los bucles dejan la UI colgada, puedes usar Application.DoEvents dentro del bucle o un Me.Refresh antes de comenzar el bucle, no es la forma correcta pero para este caso esta bien. Environment.NewLine, representa el carácter de nueva linea.

Esos comandos de consola se puede llevar fácilmente a código con ayuda de IO.File, claro es solo una aclaración porque no se si necesitas a juro hacerlo en consola ;)


En línea

La Fé Mueve Montañas...
                                    ...De Dinero

La programación es más que un trabajo es más que un hobby es una pasión...
Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.818



Ver Perfil
Re: Mostrar el output de la CMD
« Respuesta #2 en: 25 Noviembre 2012, 22:29 pm »

Gracias Keyen,
La verdad es que el comando attrib es solo es el ejemplo con el que estoy practicando para darle uso a esta función más tarde, porque lo que si necesitaré usar son utilidades de terceros como "Mediainfo.exe" y quiero mostrar el output de ese programa en cuestión.

Ya lo he solucionado usando "appendText":

Código
  1.    Private Function attrib() As Boolean
  2.        consolebox.AppendText(vbNewLine + "[+] Deleting the attributes of the files..." + vbNewLine + vbNewLine)
  3.        Dim attrib_process As New Process()
  4.        Dim attrib_startinfo As New ProcessStartInfo()
  5.        Dim attrib_args As String = videofolder
  6.        attrib_startinfo.FileName = "cmd.exe "
  7.        attrib_startinfo.UseShellExecute = False
  8.        attrib_startinfo.CreateNoWindow = True
  9.        attrib_startinfo.Arguments = "/C dir /B /AD C:\"
  10.        attrib_startinfo.RedirectStandardOutput = True
  11.        attrib_process.EnableRaisingEvents = True
  12.        attrib_process.StartInfo = attrib_startinfo
  13.        attrib_process.Start()
  14.        Dim readerStdOut As IO.StreamReader = attrib_process.StandardOutput
  15.        Do While readerStdOut.EndOfStream = False
  16.            consolebox.AppendText(readerStdOut.ReadLine() + vbNewLine)
  17.            consolebox.SelectionStart = consolebox.Text.Length
  18.            consolebox.ScrollToCaret()
  19.        Loop
  20.        consolebox.AppendText(vbNewLine + "[OK] attributes deleted!" + vbNewLine + vbNewLine)
  21.    End Function

Saludos
« Última modificación: 25 Noviembre 2012, 22:32 pm por EleKtro H@cker » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines