Cannot find output of run() command

Hi!
I am generating a shell cut command with a series of arguments parsed from a file header.
the output of the command it redirected to a file:

cut -f 1-9,14,15 input_file > output_file

I can print the command itself into a file called mycutcommand.sh and attempt to run it from Julia:

run(`sh mycutcommand.sh`)

The script finishes with ProcessExited(0) but the output file is nowhere to be found. If I run the shell command directly it works OK. What am I doing wrong?

Here is the complete script:

query = readlines(ARGS[1]) #selected sample names
samplearray = split(read(pipeline(`head -11 $(ARGS[2])`,`tail -1`),String),r"\t")
mycutcommand = "cut -f 1-9,"

for i in query
    global mycutcommand = mycutcommand * string(findall(j -> j == i, samplearray)[1]) * "," 
end

myc = replace(mycutcommand, r",$" => " ") * string(ARGS[2]) * " > select.vcf"
commandfile = open("cutcommand.sh","w")
write(commandfile,myc)
mycmd = run(`sh ./cutcommand.sh`)

First of all, welcome to out community.

Second, this seems like a terribly contrived way of doing it. Why do you not either write the script in Bash, or in Julia, what is the reason for programmatically creating a Bash script from Julia?

Third, I am not sure of the solution for your specific problem, if you can disclose some sample data you are using it may be easier to debug.

1 Like

Hi! Thanks, I ended doing the whole process within Julia, and avoided using shell calls.

1 Like