how can I join and run a program when starting application?



  • I created a secondary application in python to grab system information and export it to a txt file

    0_1558931547585_155f6e6f-c68a-433e-a76d-d664a532002c-image.png

    I wanted to know how I can configure qt, when it starts, it picks up that file runs and then it picks up the txt file it produces on it

    0_1558931772045_a7694c78-f0be-4f53-8045-e94326d83e62-image.png

    OBS: I am using qt qml, and the program is in the root directory of the source code


  • Lifetime Qt Champion

    Hi,

    Use QProcess to run your python script.

    One thing you can do is give that script a parameter so you manage where the generated file goes from your main application and you can retrieve it's content.

    One other possibility is to give your python script the option of printing these information on the standard output and still using QProcess you can directly get that information back into your main application without the need to generate a file.



  • @SGaist yes I already tried, but I do not have the whole command because it contains " | ", forcing me to create an external script


  • Lifetime Qt Champion

    Can you explain more precisely what you are trying to run ?



  • @SGaist I'm trying to run a file that takes the name of the cpu and gpu and the gpu corporation "NVIDIA OR AMD"

    But does not it have a way in which the program takes the root directory where it is automatically? because then I just need to speak the folder where the executable is



  • @Nathan-Miguel
    It's getting really unclear (to me at least) what you are asking now. Is it about specifying the path to an executable you want to run? Is it about passing arguments to it? What | does the command have in it? Why not at least tell us exactly what command you're trying to run?!

    If you have an external command you have written, you might prefer to just have it write whatever to its standard output rather than to a file which you have to create somewhere. You can then use https://doc.qt.io/qt-5/qprocess.html#readAllStandardOutput to read back the text and not have to have file creation & reading. And BTW creating dynamic/temporary files in the folder where an executable lives, if that is what you are proposing to do, is not a good idea.



  • @JonB I managed to make the program run, but the txt file is being created in the wrong place

    rootdir: E:\Git\Denoiser-Script\QML_C++\build-Denosier-Desktop_Qt_5_12_3_MSVC2017_64bit2-Debug\debug

    location where the file should exit: E:\Git\Denoiser-Script\QML_C++\build-Denosier-Desktop_Qt_5_12_3_MSVC2017_64bit2-Debug\debug\sysinfo

    location of file output: E:\Git\Denoiser-Script\QML_C++\build-Denosier-Desktop_Qt_5_12_3_MSVC2017_64bit2-Debug

    0_1559246135618_21f8d4b9-bbff-487c-a169-622953f26e95-image.png

    QString systeminfo::getsysHardware()
    {
        QString rootDir = QCoreApplication::applicationDirPath();
        QString appDirWindows = "/sysinfo/main.exe";
        QString appDirLinux = "/sysinfo/main";
        QString output;
        QString sysName = getsysType();
    
        QProcess process;
    
        if (sysName == "WINDOWS") {
            process.start(rootDir+appDirWindows);
            process.waitForFinished();
    
    
        }
        else if (sysName == "LINUX") {
    
        }
    
        return rootDir;
    }
    


  • @Nathan-Miguel
    But it is the process you run (main.exe) which creates this systeminfo.txt in some directory, is it not? Yet you are showing the code of your Qt application which runs the main.exe? Are you now talking about what the current directory will be for the main.exe you run from your Qt program (perhaps because it creates systeminfo.txt without specifying a path)?? I'm lost....

    As I suggested before, this would still be simpler anyway if you chose not to do it via a temporary file somewhere in your executable's directory area. Which is waiting to bite you if & when you distribute your application. But as you please.


  • Banned

    This post is deleted!


  • @JonB yes, but when the program executes it does not create the txt file in the same directory as main.exe is, making it impossible for me to get this txt



  • @Nathan-Miguel

    As I said/suspevted:

    • You show us the code of your Qt application, which does not create the file, so it does not help.

    • Nowhere do you you show whatever code does create the file, so since we cannot see that we cannot advise what it is you need to do.

    • I wrote above:

    Are you now talking about what the current directory will be for the main.exe you run from your Qt program (perhaps because it creates systeminfo.txt without specifying a path)??

    but you didn't reply to that. If you want help, you'll need to provide information.


 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.