• EnglishSpanishGermanFrenchPolishChinese (Traditional)


EnglishSpanishGermanFrenchPolishChinese (Traditional)

Operating systems, scripting, PowerShell and security

Operating systems, software development, scripting, PowerShell tips, network and security

Menú principal
  • Categorías
  • Cursos
  • Libro de PowerShell (nivel medio)
  • Libro de PowerShell (nivel avanzado)
  • Lo mejor
  • Lo último
  • Proyectos
  • Contactar
Ir al contenido

Ejercicios de PowerShell: crear un interfaz simple que realice la operación de suma, resta y multiplicación mediante la llamada a un script en Bash utilizando WSL

Contenidos

  • Ejemplo de script suma en Bash
  • Script en PowerShell que crear el interfaz y llama al script en Bash con WSL

Ejemplo de script suma en Bash

Shell
1
echo $1+$2 | bc

Script en PowerShell que crear el interfaz y llama al script en Bash con WSL

PowerShell
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
$form = [System.Windows.Forms.Form] @{
    Text = 'Mi formulario'
}
$Label1 = [System.Windows.Forms.Label] @{
    Text = "Número 1"
    Location = "40,20"
}
$TextBox1 = [System.Windows.Forms.TextBox] @{
    Text = ""
    Location = "150,20"
}
$Label2 = [System.Windows.Forms.Label] @{
    Text = "Número 2"
    Location = "40,50"
}
$TextBox2 = [System.Windows.Forms.TextBox] @{
    Text = ""
    Location = "150,50"
}
$Button1 = [System.Windows.Forms.Button] @{
    Text = "+"
    Location = "20,100"
}
$Button2 = [System.Windows.Forms.Button] @{
    Text = "-"
    Location = "110,100"
}
$Button3 = [System.Windows.Forms.Button] @{
    Text = "*"
    Location = "200,100"
}
$TextBox3 = [System.Windows.Forms.TextBox] @{
    Text = ""
    Location = "100,150"
}
 
function suma()
{
    $num1 = [Int]$TextBox1.text
    $num2 = [Int]$TextBox2.text
    $suma = wsl sh /root/suma.sh $num1 $num2
    $TextBox3.Text = $suma
}
 
function resta()
{
    $num1 = [Int]$TextBox1.text
    $num2 = [Int]$TextBox2.text
    $resta = wsl sh /root/resta.sh $num1 $num2
    $TextBox3.Text = $resta
}
 
function multi()
{
    $num1 = [Int]$TextBox1.text
    $num2 = [Int]$TextBox2.text
    $multi = wsl sh /root/multi.sh $num1 $num2
    $TextBox3.Text = $multi
}
 
$Button1.add_click({suma})
$Button2.add_click({resta})
$Button3.add_click({multi})
 
$form.Controls.Add($Label1)
$form.Controls.Add($TextBox1)
$form.Controls.Add($Label2)
$form.Controls.Add($TextBox2)
$form.Controls.Add($Button1)
$form.Controls.Add($Button2)
$form.Controls.Add($Button3)
$form.Controls.Add($TextBox3)
$form.ShowDialog()
Publicado el día 18 de marzo de 2021

CATEGORÍAS

Bash, PowerShell

ETIQUETAS

Bash, Echo, Ejercicios de PowerShell, Function, Jesús Niño, Jesús Niño Camazón, Script, showdialog, System.Windows.Forms, System.Windows.Forms.Form, System.Windows.Forms.Label, Windows, Windows.Forms.Form, WSL

MÁS

  • Escribir y un mensaje en una caja de texto y hacer click en un botón de un formulario de PowerShell de forma automática utilizando SendMessage y FindWindowEx de user32.dll
  • Ejercicios de PowerShell: crear un interfaz simple que realice la operación de suma, resta y multiplicación
  • Crear un formulario con botones que sean los números del 1 al 9 y cada vez que se pulsa un número se añada a una caja de texto en PowerShell
  • 13. Interfaces de usuario gráficas en PowerShell (nivel intermedio)
  • Buscar el nombre de una clase de un formulario en PowerShell con Microsoft Spy++ y escribir un mensaje en una caja de texto desde PowerShell
  • Ejercicios de PowerShell: realizar operaciones en un equipo remoto
Jesusninoc utiliza cookies: saber más aquí.