Error with setting TZ=UTC when running touch in Julia

Hi,

I wanted to run the unix command in Julia as follows:

run(`TZ=UTC touch -t "YYMMDDhhmm" filename`)

but got an IOError, assuming that I am in a different time zone from UTC and wanted to set the timestamp of a file in UTC. The above works without TZ=UTC, but the timestamp is set according to my local time zone.

The Cmd literal is not spawning a shell, it spawns processes directly. Prepending environment variables like that is a feature of your shell, not of spawning a process. To influence environment variables of spawned processes, use addenv.

7 Likes

Thanks!, I made it by using the following:

run(addenv(`touch -t "YYMMDDhhmm" filename`, "TZ" => "UTC"));
2 Likes