How to use os.system with Python and Django

Asked

Viewed 172 times

0

I’m a beginner in Django and I got caught up in the following problem:

I’d like to execute the command:

os.system("blastp -query " + proteina.name + " -subject " + multi_fasta.name + " -outfmt=6 > resultado.txt")

ps: ignore the structure, "blastp - query" is a command to perform the Alignment between the files "proteina.name" and "multi_fasta.name" (coming from a page by POST) and present to me the result in a file "result.txt".

What I noticed is that when running this command, Django tries to find the files in the "root" of my Project, but in case they are not saved there, but in a specific directory that I created for the UPLOADS called "media".

For example, this is the root of my project:

C:\Repositorios_GIT\Beta-TCC\BetaTCC

Here he is trying to search the files (showing error) and creating the file "result.txt".

Follows the error by presenting:

Command line argument error: Argument "subject". File is not accessible:  `fasta.txt'

This error happens because my file "fasta.txt" was saved inside a specific directory, the following:

C:\Repositorios_GIT\Beta-TCC\BetaTCC\media

What I would like to do is carry out the "os.system" command inside the respective directory to be able to find my files saved by upload. Is there any way or way to perform this command?

I tried to run "os.system(cd media)" and then the mentioned command, but in the same way I got the same error.

1 answer

0

Update

I was able to solve the problem by adding the "Directory" that the files were in the terminal command itself, inside os.system, follows the solution:

        os.system("blastp -query media/" + proteina.name + " -subject media/" + multi_fasta.name + " -outfmt=6 > media/resultado.txt")

Browser other questions tagged

You are not signed in. Login or sign up in order to post.