Triple quote with a variable?

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Mike Kletz Mike Kletz 2 months, 1 week ago.

  • Author
    Posts
  • #70615
    Profile photo of Mike Kletz
    Mike Kletz
    Participant

    I'm having issues making ArugmentList on Start-Process respect special characters and my google fu is failing me.

    This script block works fine

    Start-Process .\process.exe -ArgumentList """D:\Folder\[] Derp.txt"""

    But I cannot find a way to make it work with $FileName instead of D:\Folder\[] Derp.txt

  • #70619
    Profile photo of Rob Simmers
    Rob Simmers
    Participant

    A couple of things. If you look at the documentation for Start-Process, ArgumentList is a string array (string[]). Second, when you use double qoutes, Powershell will attempt to resolve that string and expand variables, etc. versus single qoutes are literal.

    Try this:

    $path = "D:\Folder\[]"
    $fileName = "Derp.txt"
    
    Start-Process .\process.exe -ArgumentList $path, $fileName
    

    If that still doesn't work, try changing the double qoutes to single qoutes to basically force Powershell to treat the variables as strings.

    • #70795
      Profile photo of Mike Kletz
      Mike Kletz
      Participant

      Thanks for the response! I'll give this a shot tonight.

You must be logged in to reply to this topic.