Skip to main content
Inspiring
January 31, 2024
Question

Using io.popen to run an executable with a space in its path

  • January 31, 2024
  • 1 reply
  • 815 views

So I have an executable which I'm trying to run in a plugin using lua's io.popen. The path has a space in it and I can't for the life of me figure out how to escape the path. I've tried a variety of quotes, single and double and I've tried using gsub to escape the spaces - s = s:gsub( ' ', '\\') - but it's beibng stubborn. Any thoughts appreciated.

 

MacOs, btw.

This topic has been closed for replies.

1 reply

Inspiring
January 31, 2024

I believe that there is a missing spave after \\

I use this:

string.gsub(SourceDir, " ", "\\ ")

 

kimaldisAuthor
Inspiring
January 31, 2024

No, there's two backslashes there. I've tried 1,2,3,4 and single quotes. in the gsub  plus all variations of single and double quotes around the path.;.

Inspiring
January 31, 2024

Well i'm quite new at this also so:

So this is a path  with space

local SourceDir = "/Users/pxxxx/Library/Mobile Documents/com~apple~CloudDocs/_CFExports/854 kopie.zip"

 

and this solves it

string.gsub(SourceDir, " ", "\\ ")