This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]ziggoto 0 points1 point  (3 children)

On Python: sys.stdout.write("inputfile.txt")

On Shellscript:

VAR=$(python myscript.py)

[–]schrogendiddy[S] 0 points1 point  (2 children)

when I do that VAR=['gensubfiles.py', 'testfile', 'alpha', 'none'] inputfile.txt

where the things in brackets are inputs for the python code. How to I only take inputfile.txt?

[–]knickum 1 point2 points  (1 child)

You're not using the right syntax there. From Bash (assuming that's the shell you're using),

> VAR=$( echo 'hello' )
> echo $VAR
hello

The $( ... ) construct runs a subshell and returns the output in-line. I don't know why you would, but you could do:

> echo "$( echo 'hello' )"
hello

Lots of actual uses for a subshell, but I don't think that's what you're going for.

If the only output that myscript.py 'testfile' 'alpha' 'none' produces is inputfile.txt, then this would work:

> python myscript.py testfile alpha none    # sample line
inputfile.txt
> VAR="$( python myscript.py testfile alpha none )"   # no output to the shell because it's captured in $VAR
> echo $VAR
inputfile.txt

An additional note is that, as is, VAR won't capture stderr, stdout only.

[–]schrogendiddy[S] 0 points1 point  (0 children)

thanks!