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!

2
  • 1
    looks like this is your requirement stackoverflow.com/questions/21963270/… Commented Nov 26, 2019 at 9:06
  • 1
    Are you looking for python3 main.py > your_text_file.txt? Commented Nov 26, 2019 at 9:07

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

4 Comments

For completeness: in some situation output might also be written to stderr, then you need to use &> instead of just >.
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!
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.
@Roverflow the space between > and output_text.txt is important

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.