08.02.2022 Views

batch-file-es Windows

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

línea

Usando el comando POWERSHELL , podemos ejecutar un comando de 1 línea directamente desde un

script por lotes, sin ningún archivo temporal.

Aquí está la sintaxis.

powershell.exe -Command <yourPowershellCommandHere>

También es posible que desee incluir otras banderas, como -Nologo para mejorar el resultado real.

Powershell / batch híbrido sin archivos temporales

Este es el enfoque propuesto por el usuario rojo de stackoverflow que también puede manejar los

argumentos de la línea de comando:

<# : batch portion

@echo off & setlocal

(for %%I in ("%~f0";%*) do @echo(%%~I) | ^

powershell -noprofile "$argv = $input | ?{$_}; iex (${%~f0} | out-string)"

goto :EOF

: end batch / begin powershell #>

"Result:"

$argv | %{ "`$argv[{0}]: $_" -f $i++ }

llamado así:

Producirá:

psbatch.bat arg1 "Esto es arg2" arg3

Result:

$argv[0]: C:\Users\rojo\Desktop\test.bat

$argv[1]: arg1

$argv[2]: This is arg2

$argv[3]: arg3

Lea Archivos por lotes e híbridos Powershell en línea: https://riptutorial.com/es/batchfile/topic/10711/archivos-por-lotes-e-hibridos-powershell

https://riptutorial.com/es/home 15

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!