V
V
Vlad_beg2019-02-07 10:20:34
PowerShell
Vlad_beg, 2019-02-07 10:20:34

How to correctly execute a command along with an element from an array in Powershell?

There is an array in which Python modules are stored, it is required to execute the command pip install+ module from the array for each element.
It gives the following error:

& : The name "pip install urllib" is not recognized as the name of a cmdlet, function, script file, or executable. Check
the spelling of the name and the presence and correctness of the path, then repeat
experience.
$modules = "urllib", "pandas", "selenium", "requests", "numpy"
for($i=0; $i -lt $modules.length; $i++) {
& "pip install $($modules [$i])"
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
azarij, 2019-02-07
@Vlad_beg

try moving the quote:
& "pip install $($modules[$i])"
like this:
& "pip" install $($modules[$i])
ps without quotes, this line also works fine. I really only on cats, ugh, I tried ping -n 1....

C
Crovax, 2019-02-07
@Crovax

Maybe so:

$modules.ForEach( {
        Start-Process -FilePath "<path_to_pip>pip.exe" -ArgumentList "install $_" -PassThru -Wait
    }
)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question