I'm sorry if this question is a dupe, but I looked at this post and this post, yet was still unable to find a solution.
I just want to execute the following bash command in my Python script to get the current epoch timestamp integer via NodeJS:
node -e "console.log(Date.now());"
The output is as expected, but when I run this in Python:
nodejs_list = ["node", "-e", '"console.log(Date.now());"']
node_time = subprocess.run(
nodejs_list,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
print(node_time)
All I'm able to get is the CompletedProcess()
output, but not the time integer:
CompletedProcess(args=['node', '-e', '"console.log(Date.now());"'], returncode=0, stdout='', stderr='')
I've even tried:
subprocess.run(nodejs_list, capture_output=True, text=True).stdout.strip("\n")
And:
subprocess.check_output(nodejs_list)
But these don't return what I need either.
I'm assuming it's because Python is unable to capture the output of Node's console.log()
or something. Is there someway to "flush" the NodeJS output? What am I doing wrong here?