2

I am using a speech-to-text example from Microsoft example here.

After following the steps, we can run the example with this command (in command prompt)

python3 main.py 

And, in the command prompt all the results are showed. Great!

However, I want to save all the results into a file (could be JSON, txt, csv...). I saw on Stackoverflow some other persons with the same issue here (however this is not really working in my example), and I knew from a previous project that I could save results to a JSON file (with Scrapy), with a command like this:

scrapy crawl Script -o name_json_file.json

Therefore my question: Can I - directly save - all the results (that the Command Prompt shows) to a file when using the command prompt? And if not, what is the best (alternative) way to save the outputs in a file?

Many thanks!

R overflow
  • 1,292
  • 2
  • 17
  • 37
  • 1
    looks like this is your requirement https://stackoverflow.com/questions/21963270/how-to-execute-a-python-script-and-write-output-to-txt-file – nithin Nov 26 '19 at 09:06
  • 1
    Are you looking for `python3 main.py > your_text_file.txt`? – shaik moeed Nov 26 '19 at 09:07

1 Answers1

3

What you are looking for is

YOUR-COMMAND > c:\PATH\TO\FOLDER\OUTPUT.txt

so in your case its

python3 main.py > c:\PATH\TO\FOLDER\OUTPUT.txt

If you want to save and also view the output you can do

python3 main.py > c:\PATH\TO\FOLDER\OUTPUT.txt | type
Caleb Njiiri
  • 1,563
  • 1
  • 11
  • 20
  • 1
    For completeness: in some situation output might also be written to `stderr`, then you need to use `&>` instead of just `>`. – Klaus D. Nov 26 '19 at 09:13
  • Looks good! Especially the last one is interesting for my example. However, I receive a "The syntax is incorrect" when trying python main.py >output_text.txt | type are you sure that the syntax is ok? Thanks in advance! – R overflow Nov 26 '19 at 09:47
  • Yeah the syntax is fine ensure you are using the right version of python. In the comment you wrote python main.py but in the question and the instructions it says python3 main.py. – Caleb Njiiri Nov 26 '19 at 10:33
  • @Roverflow the space between > and output_text.txt is important – ElmoVanKielmo Nov 26 '19 at 11:24