Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7974131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:17:14+00:00 2026-06-04T08:17:14+00:00

I have code like following, it’s ok, but I have 2 question about it.

  • 0

I have code like following, it’s ok, but I have 2 question about it.

1) If I assign some illegal para to sh, for example @”ls – l”, then the outString is null. That is to say, it can not capture the error warning “ls: -: No such file or directory
ls: l: No such file or directory”. How can I deal with it?

2) How can I implement this function: given the app’s current directory is “/user/Doc”, and I perform sh = @”cd /”, then I perform sh = @”ls -l” to see the content under the “/”
directory at next loop. But when new loop starts, the current directory resume to “/user/Doc”. How can I remain the task environment of last loop?

Furthermore, can I remain a persistent task to run “/bin/sh”,just like work on the Terminal directly?

NSString *sh = @"ls -l";
while(sh != @"end"){
    NSTask *shData = [[NSTask alloc] init];
    [shData setLaunchPath: @"/bin/sh"];

    NSArray *args;
    args = [NSArray arrayWithObjects: @"-c", sh, nil];
    [shData setArguments: args];

    NSPipe *myPipe;
    myPipe = [NSPipe pipe];
    [shData setStandardOutput: myPipe];
    [shData setStandardInput:[NSPipe pipe]];

    NSFileHandle *file;
    file = [myPipe fileHandleForReading];

    [shData launch];

    NSData *data1;    
    data1 = [file readDataToEndOfFile];

    NSString *outString;
    outString = [[NSString alloc] initWithData: data1 encoding: NSUTF8StringEncoding];

    NSLog(@"%@",outString);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:17:15+00:00Added an answer on June 4, 2026 at 8:17 am
    1. That string is on standard error, not standard output. Since you don’t check the error stream, you won’t find it.

    2. That’s not how subshells work. Google for “why is cd a shell builtin” for lots of information.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have some code like the following, and that processData gets executed
Using the razor view engine, I have some code like the following: @Html.TextAreaFor(model =>
I have some code like the following that I'm running in a debugger in
For example if i have code like the following both Buttons are disabled: <RichTextBox>
If i have some code like the following: short myShortA = 54; short myShortB
I have some PHP code like the following (simplified): <ul> <?php for ($Index =
I have some code that looks like the following coming back from an XHR
I have code like following: switch(sort.Column) { case code: model = (sort.Direction == SortDirection.Ascending)
I have code like the following in a UserControl: Protected Overrides Sub Render(ByVal writer
I have code that looks like the following: //unrelated code snipped resolver.reset(new tcp::resolver(iosvc)); tcp::resolver::query

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.