• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTask: how to launch a binary as if I launched it via terminal?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTask: how to launch a binary as if I launched it via terminal?


  • Subject: Re: NSTask: how to launch a binary as if I launched it via terminal?
  • From: Bryan Vines <email@hidden>
  • Date: Mon, 14 Apr 2014 10:39:12 -0500

Colas,

Bash’s -c option expects commands in a string which follows. Therefore, this will work: I’m using /usr/bin/touch as an example, rather than your example of pico, which is an interactive text editor.

    NSTask * myTask = [[NSTask alloc]init];

    NSArray * arguments = @[@"-c", @"/usr/bin/touch /Users/colas/touchedFile.txt", @"-l"];

    [myTask setCurrentDirectoryPath:@"/"];
    [myTask setLaunchPath:@"/bin/bash"];
    [myTask setArguments:arguments];

    [myTask launch];

This will touch a file named “touchedFile.txt” at the root of your home directory.

—
Bryan


On Apr 14, 2014, at 10:08 AM, Colas B <email@hidden> wrote:

> OK.
>
> But without the simple quotes, it also fails.
>
> With the quotes, the error is
> /bin/bash: pico /Users/colas/myfile.txt: No such file or directory
> Without the quotes, the error is
> Error opening terminal: unknown.
>
> Thanks!
> Le Lundi 14 avril 2014 16h19, Jerry Krinock <email@hidden> a écrit :
>
> From documentation of -[NSTask setArguments:] :
>
> "The strings in arguments do not undergo shell expansion, so you do not need to do special quoting”
>
> I don’t know what they mean by “special”, but anyhow, the ‘ ' you put around your last argument will be passed to your tool and cause it to fail.
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >NSTask: how to launch a binary as if I launched it via terminal? (From: Colas B <email@hidden>)
 >Re: NSTask: how to launch a binary as if I launched it via terminal? (From: Jerry Krinock <email@hidden>)
 >Re: NSTask: how to launch a binary as if I launched it via terminal? (From: Colas B <email@hidden>)

  • Prev by Date: Re: NSTask: how to launch a binary as if I launched it via terminal?
  • Next by Date: Re: NSTask: how to launch a binary as if I launched it via terminal?
  • Previous by thread: Re: NSTask: how to launch a binary as if I launched it via terminal?
  • Next by thread: Re: NSTask: how to launch a binary as if I launched it via terminal?
  • Index(es):
    • Date
    • Thread