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

2014-04-14 Thread Colas B
Dear cocoa-dev,


I am would like to launch a binary as if I launched it via terminal. I tried 
the following but it is not working. 

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

    NSArray * arguments = @[@-c, @-l, @'/usr/bin/pico 
/Users/colas/myfile.txt'];

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

If I execute the same commands in a terminal, it works !!

$ /bin/bash -c -l '/usr/bin/pico /Users/colas/myfile.txt'


Any remark will be appreciated !!
Thanks,

Colas
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

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

2014-04-14 Thread Jerry Krinock
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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

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

2014-04-14 Thread Bryan Vines
Colas,

Do you want your app to open a Terminal window, in which Pico has opened the 
file at /Users/colas/myfile.txt?
If that’s so, I don’t think launching it via NSTask is going to get you 
anything.

What is the end result you want to achieve?
—
Bryan Vines

On Apr 14, 2014, at 8:59 AM, Colas B colasj...@yahoo.fr wrote:

 Dear cocoa-dev,
 
 
 I am would like to launch a binary as if I launched it via terminal. I tried 
 the following but it is not working. 
 
NSTask * myTask = [[NSTask alloc] init];
 
NSArray * arguments = @[@-c, @-l, @'/usr/bin/pico 
 /Users/colas/myfile.txt'];
 
[myTask setCurrentDirectoryPath:@/];
[myTask setLaunchPath:@/bin/bash];
[myTask setArguments:arguments];
 
[myTask launch] ;
 
 If I execute the same commands in a terminal, it works !!
 
 $ /bin/bash -c -l '/usr/bin/pico /Users/colas/myfile.txt'
 
 
 Any remark will be appreciated !!
 Thanks,
 
 Colas
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 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:
 https://lists.apple.com/mailman/options/cocoa-dev/bkvines%40me.com
 
 This email sent to bkvi...@me.com
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

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

2014-04-14 Thread Colas B
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 je...@ieee.org 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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

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

2014-04-14 Thread Fritz Anderson
On 14 Apr 2014, at 10:08 AM, Colas B colasj...@yahoo.fr 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 je...@ieee.org 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.
 ___

Try putting

/usr/bin/pico /Users/colas/myfile.txt

into separate items in the argument NSArray. I find the man page ambiguous, and 
I lack direct experience, but that may be what bash expects.

I can’t guarantee that this will solve the larger problem of whether the effect 
would be to launch Terminal.app and execute the command, but it’s worth trying.

— F


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

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

2014-04-14 Thread Ken Thomases
On Apr 14, 2014, at 10:08 AM, Colas B wrote:

 Without the quotes, the error is
 Error opening terminal: unknown.

Terminal doesn't just run the shell (which, in turn, runs pico).  It provides a 
window and a TTY (terminal device) for the processes to use and translates the 
I/O to the window.  This is no simple thing.  In fact, it's very complex.  It's 
not what NSTask does and, in fact, no built-in part of Cocoa does it for you.

It will be much, much simpler to simply load the file into a text view, let the 
user edit it that way, and save it back.

If you want the command to run in an actual Terminal window, you can use 
AppleScript to control Terminal and have it create a window and run a command 
within it.

Regards,
Ken


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

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

2014-04-14 Thread Colas

 Try putting
 
 /usr/bin/pico /Users/colas/myfile.txt
 
 into separate items in the argument NSArray. I find the man page ambiguous, 
 and I lack direct experience, but that may be what bash expects.
 
 

It is not working, unfortunately.

 I can’t guarantee that this will solve the larger problem of whether the 
 effect would be to launch Terminal.app and execute the command, 

I don’t want Terminal to be launched. I just want my program (here, in this 
example pico) to be launched from a login shell.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

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

2014-04-14 Thread Bryan Vines
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 colasj...@yahoo.fr 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 je...@ieee.org 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 (Cocoa-dev@lists.apple.com)
 
 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:
 https://lists.apple.com/mailman/options/cocoa-dev/bkvines%40me.com
 
 This email sent to bkvi...@me.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

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

2014-04-14 Thread Colas

Le 14 avr. 2014 à 17:07, Bryan Vines bkvi...@me.com a écrit :

 Hi Colas,
 
 Pico is an interactive text editor. I don’t think NSTask is going to give you 
 much opportunity to interact with it. Are you using Pico as an example, or 
 are you actually trying to launch Pico?
 
 If you really *are* trying to launch Pico, what do you want to do with it?

I use pico as an example.
I want to launch another program (namely pdflatex), without interacting with 
it, but I need it to be launched as if it was launched from the terminal.

My problem is that I want to launch pdflatex with the -shell-escape option. 
This option allows pdflatex to launch itself other programs. But, when 
pdflatex, in this context (I mean, launched via NSTask), tries to launch gnu 
plot, it fails. Whereas the same commands, typed in a terminal, succeed.

My guess (and others’) is that it is a problem of environment variables.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

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

2014-04-14 Thread Bryan Vines
Colas,

If my previous code snippet doesn’t work with pdflatex, NSTask has a 
-setEnvironment method; it may allow you to set your task’s environment 
variables.

—
Bryan Vines


On Apr 14, 2014, at 10:40 AM, Colas colasj...@yahoo.fr wrote:

 My problem is that I want to launch pdflatex with the -shell-escape option. 
 This option allows pdflatex to launch itself other programs. But, when 
 pdflatex, in this context (I mean, launched via NSTask), tries to launch gnu 
 plot, it fails. Whereas the same commands, typed in a terminal, succeed.
 
 My guess (and others’) is that it is a problem of environment variables.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

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

2014-04-14 Thread Colas
Bryan,

I am trying to adapt your code to pdflatex. I hope it will work!!!

It seems that putting the option -l at the end was very important.
Do you know why? I have to admit that I put these « -c » and « -l » options 
thanks to other answers, but I don’t know what they are doing.

Thanks very much !!

Le 14 avr. 2014 à 17:43, Bryan Vines bkvi...@me.com a écrit :

 Colas,
 
 If my previous code snippet doesn’t work with pdflatex, NSTask has a 
 -setEnvironment method; it may allow you to set your task’s environment 
 variables.
 
 —
 Bryan Vines
 
 
 On Apr 14, 2014, at 10:40 AM, Colas colasj...@yahoo.fr wrote:
 
 My problem is that I want to launch pdflatex with the -shell-escape option. 
 This option allows pdflatex to launch itself other programs. But, when 
 pdflatex, in this context (I mean, launched via NSTask), tries to launch gnu 
 plot, it fails. Whereas the same commands, typed in a terminal, succeed.
 
 My guess (and others’) is that it is a problem of environment variables.
 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

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

2014-04-14 Thread Colas
Unfortunately, it is not working. Gnuplot is complaining.

! Package pgfplots Error: Sorry, the gnuplot-result file ‘myFile.pgf-plot.t
able' could not be found. Maybe you need to enable the shell-escape feature? Fo
r pdflatex, this is ' pdflatex -shell-escape'. You can also invoke ' gnuplo
t file.gnuplot' manually on the respective gnuplot file..

(I give the option —shell-escape to pdflatex)
The error I get in xcode is

[;sh: gnuplot: command not found.

Thanks also for the idea of -setEnvironment. I will try.

Le 14 avr. 2014 à 17:43, Bryan Vines bkvi...@me.com a écrit :

 Colas,
 
 If my previous code snippet doesn’t work with pdflatex, NSTask has a 
 -setEnvironment method; it may allow you to set your task’s environment 
 variables.
 
 —
 Bryan Vines
 
 
 On Apr 14, 2014, at 10:40 AM, Colas colasj...@yahoo.fr wrote:
 
 My problem is that I want to launch pdflatex with the -shell-escape option. 
 This option allows pdflatex to launch itself other programs. But, when 
 pdflatex, in this context (I mean, launched via NSTask), tries to launch gnu 
 plot, it fails. Whereas the same commands, typed in a terminal, succeed.
 
 My guess (and others’) is that it is a problem of environment variables.
 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

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

2014-04-14 Thread Colas
Thanks to everyone for helping !!!
Using setEnvironment made it easily. I was looking for a complicated solution 
when the solution was not so difficult.

Le 14 avr. 2014 à 17:59, Colas colasj...@yahoo.fr a écrit :

 Thanks also for the idea of -setEnvironment. I will try.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com