From 20c836954dce8f0d07788003b44e44990ac3a29d Mon Sep 17 00:00:00 2001 From: Bibiko Date: Sun, 21 Nov 2010 21:25:38 +0000 Subject: =?UTF-8?q?=E2=80=A2=20run=20a=20normal=20bash=20script=20without?= =?UTF-8?q?=20#!=20first=20line=20as=20/bin/sh=20file=20whereby=20stdout?= =?UTF-8?q?=20is=20redirected?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPStringAdditions.m | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'Source') diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m index 09f37866..be91fa0b 100644 --- a/Source/SPStringAdditions.m +++ b/Source/SPStringAdditions.m @@ -452,7 +452,17 @@ NSBeep(); NSLog(@"Couldn't write script file."); } - + } + } else { + [scriptHeaderArguments addObject:@"/bin/sh"]; + NSError *writeError = nil; + [self writeToFile:scriptFilePath atomically:YES encoding:NSUTF8StringEncoding error:writeError]; + if(writeError == nil) { + redirectForScript = YES; + [scriptHeaderArguments addObject:scriptFilePath]; + } else { + NSBeep(); + NSLog(@"Couldn't write script file."); } } @@ -491,10 +501,7 @@ [bashTask setCurrentDirectoryPath:[shellEnvironment objectForKey:@"SP_BUNDLE_PATH"]]; // STDOUT will be redirected to /tmp/SP_BUNDLE_OUTPUT_FILE in order to avoid nasty pipe programming due to block size reading - if(redirectForScript) - [bashTask setArguments:[NSArray arrayWithObjects:@"-c", [NSString stringWithFormat:@"%@ > %@", [scriptHeaderArguments componentsJoinedByString:@" "], stdoutFilePath], nil]]; - else - [bashTask setArguments:[NSArray arrayWithObjects:@"-c", [NSString stringWithFormat:@"%@ > %@", self, stdoutFilePath], nil]]; + [bashTask setArguments:[NSArray arrayWithObjects:@"-c", [NSString stringWithFormat:@"%@ > %@", [scriptHeaderArguments componentsJoinedByString:@" "], stdoutFilePath], nil]]; NSPipe *stderr_pipe = [NSPipe pipe]; [bashTask setStandardError:stderr_pipe]; -- cgit v1.2.3