15452

Powershell | Unable to perform command with space character

Can anyone explain to me why:

iex "C:\Program Files\test\test.exe"

Returns:

C:\Program : The term 'C:\Program' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + C:\Program Files\test\test.exe + ~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Program:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

<hr>

I've tried to get this working multiple different ways:

    <li>Wrapping the text in ()</li> <li>Putting the string into a variable and passing it as a variable instead</li> <li>Using single quotes</li> <li>Using double quotes</li> </ul>

    I don't know how else I can get it to realize that the entire string must be run, not just the first word.

    <hr>

    <strong>Post-answered example</strong>

    The question has been answered. Here is something I was trying to get working:

    $tool = "C:\Windows\System32\cmd.exe" $param = "/c ping google.com -n 1" $test = & $tool $param Write-Host $test

    It turns out that the line with & does NOT work with double quotes "" in this instance, and actually worked without them. I think this has to do with there being arguments/parameters involved.

    Answer1:

    Use the & operator together with quotes:

    & "C:\Program Files\test\test.exe" <hr>

    From help about_operators:

    & Call operator Runs a command, script, or script block. The call operator, also known as the "invocation operator," lets you run commands that are stored in variables and represented by strings. Because the call operator does not parse the command, it cannot interpret command parameters. C:\PS> $c = "get-executionpolicy" C:\PS> $c get-executionpolicy C:\PS> & $c AllSigned

Recommend

  • .htaccess rewriteRule conflict
  • Amazon S3 - How do I download objects owned by anonymous user?
  • grep with wildcards stored in a file
  • Matlab: creating a (k+1)-tensor from a list of k-tensors
  • How to match ',' in PIG?
  • Writing an RDA to CSV in R
  • Sort by id element using jQuery [duplicate]
  • Can I make OCaml produce stack traces on uncaught exceptions?
  • How to clear out the contents of a map when clear() method call throws UnsupportedOperationException
  • Getting a generic method to infer the type parameter from the runtime type
  • Finding parents in a tree hierarchy for a given child LINQ (lambda expression)
  • SSH in Bash Script Messing Up File Read
  • Build Matrix of Comparisons in SQl Server
  • Yii2: Using Kartik Depdrop Widget?
  • How to determine the CCSID used in CPYFRMIMPF command?
  • c++ using primitive types as a base class
  • php is_file always return false
  • Wrapping a c#/WPF GUI around c++/cli around native c++
  • Creating NSCollectionView with datasource programatically
  • Javascript/Jquery runs fast in desktop browsers, but slow in mobile/smartphone browsers…should I spl
  • Tamper-proof configuration files in .NET?
  • Extracting HTML between tags
  • Repeat a vertical line on every page in Report Builder / SSRS
  • Android screen density dpi vs ppi
  • Bug in WPF DataGrid
  • Why doesn't :active or :focus work on text links in webkit? (safari & chrome)
  • Validaiting emails with Net.Mail MailAddress
  • MySQL WHERE-condition in procedure ignored
  • Knitr HTML Loop - Some HTML output, some R output
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • Javascript + PHP Encryption with pidCrypt
  • Web-crawler for facebook in python
  • WOWZA + RTMP + HTML5 Playback?
  • Matrix multiplication with MKL
  • trying to dynamically update Highchart column chart but series undefined
  • Hits per day in Google Big Query
  • File not found error Google Drive API
  • How does Linux kernel interrupt the application?
  • Converting MP3 duration time
  • java string with new operator and a literal