Same command giving different results when run in CLI and when as an argument for os.system()

Viewed 149

I'm using python to try and scrape twitter data using SNSCRAPE, and for that I need to run the following example command to get the output I want:

snscrape --max-results 100 twitter-search '@Tesla @Elonmusk' > scrapedtweets.txt

When run on the terminal, it sends the output directly to a text file named 'scrapedtweets'. But when I plug this string into os.system like so:

os.system("snscrape --max-results 100 twitter-search '@Tesla @Elonmusk' > scrapedtweets.txt")

I get an error code '2', and scrapedtweets.txt remains blank.

I should mention that the command works perfectly in os.system() when there are no @ symbols involved in the command, which leads me to think that it is being parsed funny by the function, but I have no idea what the exact problem is or how to solve it.

Or alternatively is there something wrong with how I am using os.system()?

Any and all help is appreciated.

0 Answers
Related