NSTask and whitespace

Hi! I’m trying to write an application that handles a simple “rsync” shell command task. I build an array list with the command’s arguments and create the NSTask thing:

set arrayList to {"-CaviuE", "--filter='exclude .fseventsd'", src, tgt}

set rsync to current application's NSTask's alloc's init()
tell rsync
	setStandardOutput_(outputpipe)
	setStandardError_(outputpipe)
	setLaunchPath_(cmdPath)
	setArguments_(arrayList)
	|launch|()
end tell

Note the second argument in arrayList. It contains a space character, which leads to an error and prevents the script from working. How can I circumvent whitespace in argument strings?

Try this:

set arrayList to {“-CaviuE”, quoted form of “–filter=‘exclude .fseventsd’”, src, tgt}

Thanks. But no luck. The shell command says now “No such file or folder” and seems to take that argument as a file path rather than an exclude instruction. Even when I try an argument with no whitespace character inside, like quoted form of “–stats”. Did I miss something?

Is your launchPath the full path to the command?

Yes. It’s bundled with the application and within its directory. Leaving that argument out the command works.

I’ve had another look, and I don’t think you need quoted form – your original looks correct. What error does it generate?

Meanwhile I changed the code so much, I don’t get this error again. Now it resets my read pipe when I put in this argument. (The original one.) Can’t figure out why. But I managed to circumvent that whole thing by including a rule file for rsync. That works very well. Here’s what I did for everyone, who is encountering the same issues:

set arrayList to ¬
{ ¬
	"-CaviuE", ¬
	"--exclude-from=" & (current application's NSBundle's mainBundle's pathForResource_ofType_("excludes.txt", missing value) as string), ¬
	src, tgt ¬
}

The file excludes.txt contains some lines like:

- .fseventsd

But thanks for your support, Shane!