Pass EOF instruction with Process.run

Hi guys, for some specific need I have to run this instruction with Process.run:

cat > test << "EOF"
text
EOF

But it don’t work. Why ?

I used that command in a crystal script for test:

command = [ "cat",
            ">",
            "test",
            "<<",
            "\"EOF\"",
            "text",
            "EOF"]

Process.run(command.join(" "),
                shell: true)

The file is generated but empty, why ?

Would it not be easier to do like File.write "test", "text"?

Could it be that you’re missing newlines in the Process command vs the example terminal command?

Try this:

Process.run <<-CMD, shell: true
  cat > test.file <<EOF
  text
  EOF
  CMD
1 Like

As I said in my post, it’s for a specific need. Sorry it’s just will be too long to explain.

Perfect ! Thanks a lot

:thinking: I’d be curious to know what you’re doing that you need to run shell commands that can’t be done with native Crystal methods.

1 Like

To explain in a short way, my package manager need to run some command inside another system. For that it run a generated sh script under the system via chroot. This way make things easier for the user who implement a software installer (packager). They don’t need to think about the implementation of the path.

Because the path at some point (it’s quite technical at this point) is related about 2 things:
-Is it a path related to the chroot or not?
-The package manager have the installation by chroot mode enabled or not ?

Sorry It’s just I don’t want to write a full explanation of the process, it’s too long :sweat:

You need just to understand that ISM manage the installation before any chroot are possible, that make the things even more tricky.

It not a standard package manager, it really build everything from zero

Just to show you, after my last update , this is now how look an installer for a software , for example Gcc. I think I really made the API very easy to read and understand

It’s still technical of course , but much easier to read