[Python] Can I tell Python to execute command line in cmd?

Discussão em 'Python' iniciado por Stack, Fevereiro 25, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working on a personal project as a very amateur programmer and to do this, I need to have python tell cmd to run an external program via command line.

    For example, I need to chdir ("C:\blah\blah") on Python, and run externalprogram -w "<destination>\newName.fileType>" "<source>\*.*".

    I'm very lost in how to do this and any help would be greatly appreciated.

    So far my code looks like this

    import os

    os.chdir('C:\Program Files (x86)\<externalProgram>')
    os.system('<externalCommand> "<destination>\file.fileType" "<source>\*.*"')


    Still can't get it to work though no errors are being posted to the shell.

    Continue reading...

Compartilhe esta Página