Prince Modi
Prince Modi

Reputation: 495

Write a file using System Command

I am trying to create a file using the system command but it does not work for some reason. It just echoes the command back.

system("echo 'Hello2222, world.' >foo2.txt");
Hello2222, world. >foo2.txt

When I run the echo command in CMD, the file is created.

Upvotes: 2

Views: 432

Answers (1)

G5W
G5W

Reputation: 37641

Notice that the documentation for system says

On Windows, system does not use a shell and there is a separate function shell which passes command lines to a shell.

shell("echo 'Hello2222, world.' >foo2.txt")

will do what you want.

Upvotes: 3

Related Questions