Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

fork/exec

5 views
Skip to first unread message

D.M. Procida

unread,
Oct 20, 2021, 12:08:40 PM10/20/21
to
I'm using a tool written in Go that raises an error in macOS, and works
fine under Ubuntu:

error: cannot edit file <filename>: fork/exec /usr/local/bin/mate -w: no
such file or directory

The issue is fork/exec.

I think this is the culprit:
https://github.com/niemeyer/discedit/blob/master/main.go#L221-L224.

Any suggestions on what to try? I think it could be the way Go is
compiling the code that's the issue, rather than the code itself, but
then I am not a Go programmer at all, so I could be quite wrong about
that.

Any ideas on what to try?

Thanks,

Daniele

Richard Tobin

unread,
Oct 20, 2021, 12:25:06 PM10/20/21
to
In article <1phcx6x.n2zbz31pl2ms2N%real-not-anti...@apple-juice.co.uk>,
D.M. Procida <real-not-anti...@apple-juice.co.uk> wrote:

>error: cannot edit file <filename>: fork/exec /usr/local/bin/mate -w: no
>such file or directory

Does /usr/local/bin/mate in fact exist?

-- Richard

D.M. Procida

unread,
Oct 20, 2021, 1:12:33 PM10/20/21
to
Yes indeed. It took me a while to be certain what it was complaining
didn't exist, but it's neither /usr/local/bin/mate, onr the filename
that it's supposed to open.

/usr/local/bin/mate -w <filename> works as expected, for example.

Daniele

Richard Tobin

unread,
Oct 20, 2021, 1:55:05 PM10/20/21
to
In article <1phd121.pqmgtg14roeomN%real-not-anti...@apple-juice.co.uk>,
D.M. Procida <real-not-anti...@apple-juice.co.uk> wrote:

>> >error: cannot edit file <filename>: fork/exec /usr/local/bin/mate -w: no
>> >such file or directory

>> Does /usr/local/bin/mate in fact exist?

>Yes indeed. It took me a while to be certain what it was complaining
>didn't exist, but it's neither /usr/local/bin/mate, onr the filename
>that it's supposed to open.
>
>/usr/local/bin/mate -w <filename> works as expected, for example.

Hmm, that error message rather suggests that it is trying to execute a
program called "/usr/local/bin/mate -w", rather than
"/usr/local/bin/mate" with a "-w" argument. But if it works on some
other system, that seems unlikely.

-- Richard

Richard Tobin

unread,
Oct 20, 2021, 2:05:05 PM10/20/21
to
In article <skpku9$2e7d$1...@macpro.inf.ed.ac.uk>,
Richard Tobin <ric...@cogsci.ed.ac.uk> wrote:

>Hmm, that error message rather suggests that it is trying to execute a
>program called "/usr/local/bin/mate -w", rather than
>"/usr/local/bin/mate" with a "-w" argument. But if it works on some
>other system, that seems unlikely.

Looking at the code my guess is that you have set EDITOR to
"/usr/local/bin/mate -w", and the program expects it to just be the
path of the editor, without arguments. If you set it to
"/usr/local/bin/emacs" does it work?

If that's the problem, and it needs -w, you could create a shell
script wrapper for it.

-- Richard

Richard Tobin

unread,
Oct 20, 2021, 2:10:06 PM10/20/21
to
In article <skplnp$2ef8$1...@macpro.inf.ed.ac.uk>,
Richard Tobin <ric...@cogsci.ed.ac.uk> wrote:
>If you set it to "/usr/local/bin/emacs" does it work?

Probably "/usr/bin/emacs" on your system.

-- Richard

Bruce Horrocks

unread,
Oct 20, 2021, 6:49:00 PM10/20/21
to
It's complaining that it can't find a file called "-w".

I'm guessing that mate is using a standard library to parse filenames
and flags from the command line it receives and on Ubuntu/Linux that
standard library treats the -w as a subsequent flag whereas MacOS/BSD is
presumably treating it as a filename.

To test you could trying writing a shell script wrapper around Mate to
print out what it is receiving.

The editor command being used is being taken from the EDITOR shell
environment variable so you should hopefully only have to set that to
point to the wrapper script and nothing more.

--
Bruce Horrocks
Surrey, England

D.M. Procida

unread,
Oct 21, 2021, 3:42:26 AM10/21/21
to
Richard Tobin <ric...@cogsci.ed.ac.uk> wrote:

> In article <skpku9$2e7d$1...@macpro.inf.ed.ac.uk>,
> Richard Tobin <ric...@cogsci.ed.ac.uk> wrote:
>
> >Hmm, that error message rather suggests that it is trying to execute a
> >program called "/usr/local/bin/mate -w", rather than
> >"/usr/local/bin/mate" with a "-w" argument. But if it works on some
> >other system, that seems unlikely.
>
> Looking at the code my guess is that you have set EDITOR to
> "/usr/local/bin/mate -w", and the program expects it to just be the
> path of the editor, without arguments. If you set it to
> "/usr/local/bin/emacs" does it work?

You are absolutely right, and removing the -w makes it work again.
However, it wasn't me that set it, it was set by TextMate:

> To use TextMate as editor for subversion, git, and similar you need to
> install the mate shell command and add a line like the following to
> ~/.bashrc:
>
> export EDITOR="/usr/local/bin/mate -w"

The -w flag makes it wait for the edit to finish - which isn't needed
for this application, but is required for Git.

Daniele

Theo

unread,
Oct 21, 2021, 6:06:40 AM10/21/21
to
D.M. Procida <real-not-anti...@apple-juice.co.uk> wrote:
> Richard Tobin <ric...@cogsci.ed.ac.uk> wrote:
> You are absolutely right, and removing the -w makes it work again.
> However, it wasn't me that set it, it was set by TextMate:
>
> > To use TextMate as editor for subversion, git, and similar you need to
> > install the mate shell command and add a line like the following to
> > ~/.bashrc:
> >
> > export EDITOR="/usr/local/bin/mate -w"
>
> The -w flag makes it wait for the edit to finish - which isn't needed
> for this application, but is required for Git.

I saw this kind of thing with Python's subprocess recently.
'subprocess.run' calls execvpe() behind the scenes. The behaviour (on
Ubuntu) of some programs is different whether you have 'run in a shell'
enabled or not. I think the issue is that calling:

subprocess.run(["/usr/local/bin/mate -w"], shell=False)

expects the argument to the be name of the program, whereas:

subprocess.run(["/usr/local/bin/mate -w"], shell=True)

runs a shell and passes the string '/usr/local/bin/mate -w' to it. Being a
shell it sees the input as a shell script, does the argument separation, and
then looks for /usr/local/bin/mate with argv[1] set to '-w'.

In Python the way to run the original without a shell would have been:
subprocess.run(["/usr/local/bin/mate", "-w"])
which makes the argument separation explicit.


In my case, the problem was more like:

subprocess.run(["/blah/blah/blah.sh"], shell=False)

and calling exec on something that happened to be a shell script (which
turned out to be a hidden frontend to a real binary and so didn't have a .sh
suffix to make it obvious) didn't work without first running it in a shell.

Theo

D.M. Procida

unread,
Oct 21, 2021, 8:37:33 AM10/21/21
to
Solution implemented at
<https://github.com/niemeyer/discedit/commit/a65fc81a8c8a206a0257d605014d55d40956afda>.

The Go application now handles the case where commans include arguments.

Daniele

D.M. Procida

unread,
Oct 21, 2021, 8:37:33 AM10/21/21
to
Bruce Horrocks <07....@scorecrow.com> wrote:

> On 20/10/2021 18:51, Richard Tobin wrote:
> > In article
> > <1phd121.pqmgtg14roeomN%real-not-anti...@apple-juice.co.uk>,
> > D.M. Procida <real-not-anti...@apple-juice.co.uk> wrote:
> >
> >>>> error: cannot edit file <filename>: fork/exec /usr/local/bin/mate -w: no
> >>>> such file or directory
> >
> >>> Does /usr/local/bin/mate in fact exist?
> >
> >> Yes indeed. It took me a while to be certain what it was complaining
> >> didn't exist, but it's neither /usr/local/bin/mate, onr the filename
> >> that it's supposed to open.
> >>
> >> /usr/local/bin/mate -w <filename> works as expected, for example.
> >
> > Hmm, that error message rather suggests that it is trying to execute a
> > program called "/usr/local/bin/mate -w", rather than
> > "/usr/local/bin/mate" with a "-w" argument. But if it works on some
> > other system, that seems unlikely.
>
> It's complaining that it can't find a file called "-w".
>
> I'm guessing that mate is using a standard library to parse filenames
> and flags from the command line it receives and on Ubuntu/Linux that
> standard library treats the -w as a subsequent flag whereas MacOS/BSD is
> presumably treating it as a filename.

mate is the command line invocation of the Macintosh text editor
TextMate, and using the -w flag is the appropriate way to invoke it in
most cases.

It's only when invoked by fork/exec that it runs into an issue.

It is unusual that EDITOR should include an argument, as well as the
program?

Daniele

Richard Tobin

unread,
Oct 21, 2021, 3:30:06 PM10/21/21
to

D.M. Procida

unread,
Oct 21, 2021, 5:04:01 PM10/21/21
to
My colleague - I think he did it within about 25 minutes!

Daniele

Bruce Horrocks

unread,
Oct 21, 2021, 6:32:31 PM10/21/21
to
No - it seems quite reasonable to be able to specify any necessary
flags. How else is the parent program to know that it should add "-w"
when exec'ing?

I see from your other posts that it is now fixed, so all's well etc.
0 new messages