nvim-neotest / nvim-nio

A library for asynchronous IO in Neovim
MIT License
288 stars 8 forks source link

[help] Differences between nio.process.run and vim.fn.jobstart #14

Closed benlubas closed 5 months ago

benlubas commented 6 months ago

I'm running into a weird issue where two commands are behaving differently if they're run with vim.fn.jobstart or nio.process.run.

Specifically dvipng can't produce transparent images with process.run, but can with jobstart.

nio.process.run({
    cmd = "dvipng",
    args = {
        "-D",
        module.config.public.dpi,
        "-T tight",
        "-bg Transparent",
        "-fg 'cmyk 0.00 0.04 0.21 0.02'",
        "-o",
        png_result,
        ("%s.dvi"):format(document_name),
    },
})
-- vs:
nio.fn.jobstart(
    "dvipng -D "
    .. tostring(module.config.public.dpi)
    .. " -T tight -bg Transparent -fg 'cmyk 0.00 0.04 0.21 0.02' -o "
    .. png_result
    .. " "
    .. document_name
    .. ".dvi",
    { cwd = cwd }
)

image

vs:

image


Seems like job start does something special with the environment that it runs things in. Is there a way to mimic this with process.run or should I just use nio.fn.jobstart? if you have a concrete explanation for what's happening that'd be great too, I'd not been able to find anyone that has this problem with dvipng (but it's also probably a niche usecase).

rcarriga commented 5 months ago

I'm not familiar with dvipng but you're not correctly passing the arguments. They should all be separate in the array like this

nio.process.run({
  cmd = "dvipng",
  args = {
    "-D",
    module.config.public.dpi,
    "-T",
    "tight",
    "-bg",
    "Transparent",
    "-fg",
    "cmyk 0.00 0.04 0.21 0.02",
    "-o",
    png_result,
    ("%s.dvi"):format(document_name),
  },
})

It is not like a shell so you don't need to quote the arguments as you had with cmyk 0.00 0.04 0.21 0.02

benlubas commented 5 months ago

That works, thank you. I should read the docs a little closer next time