Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to run a .out file and store the output in a .txt file inside a docker Container?

I have built a docker Container named ubuntu-comp and run it with a volume by this command:

sudo docker run -v /home/vivek/PersonalSet/OJBh/Judge/folderrun/:/home/folderrun/ -d ubuntu-comp

This command runs successfully. Now I want to execute a command to run a file called c.out and store the output (STDOUT) in a text file called c.txt. Both files are stored in the volume directory.

Normally I’d use the command /home/folderrun/c.out > /home/folderrun/c.txt. This works fine if I run the Command in interactive mode, i.e. with the -it flag.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

but when i run the following command:

sudo docker exec -it focused_wilbur /home/folderrun/c.out > /home/folderrun/c.txt

I get the following error:

bash: /home/folderrun/c.txt: No such file or directory

I need a fix, Thanks in advanced for any help offered.

>Solution :

You can do it by passing your command to /bin/sh like this

sudo docker exec -it focused_wilbur /bin/sh -c "/home/folderrun/c.out > /home/folderrun/c.txt"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading