Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. file log output script execution windows not created on Windows
Forum Updated to NodeBB v4.3 + New Features

file log output script execution windows not created on Windows

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 3 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mourad_bilog
    wrote on last edited by
    #1

    I've passed really 2 days to search and test but nothing works. I'm really disepointed.

    In fact, from my Qt5 application, I'm executing an Oracle SQL script and I want to trace output results to a log file to know if there's any error. I'm exectuting the following command using QProcess.

    sqlplus myUser/user_pwd@orcl @"path_to_script\script_ora.sql" >"path_to_log\\exec_script.log"
    

    but the log file is not created and I really don't why. I've used static log path, I've tried to change "\" by "/" but nothing works. I've verified that I can write into the ouput path and I run the MSVS as an admin

    Can anyone tell what I'm missing or what's wrong ?

    Many thanks in advance.

    JonBJ 1 Reply Last reply
    0
    • M mourad_bilog

      I've passed really 2 days to search and test but nothing works. I'm really disepointed.

      In fact, from my Qt5 application, I'm executing an Oracle SQL script and I want to trace output results to a log file to know if there's any error. I'm exectuting the following command using QProcess.

      sqlplus myUser/user_pwd@orcl @"path_to_script\script_ora.sql" >"path_to_log\\exec_script.log"
      

      but the log file is not created and I really don't why. I've used static log path, I've tried to change "\" by "/" but nothing works. I've verified that I can write into the ouput path and I run the MSVS as an admin

      Can anyone tell what I'm missing or what's wrong ?

      Many thanks in advance.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @mourad_bilog
      You cannot do redirection --- > --- in an OS command, nothing to do with Qt. You have two approaches.

      Use cmd /c, the "shell", to do it (be careful about quoting & backslashes):

      QProcess p;
      p.start('cmd', QStringList() << "/c" << "sqlplus \"myUser/user_pwd@orcl\" \"@path_to_script\\script_ora.sql\" >\"path_to_log\\exec_script.log\"");
      

      or do the redirection form Qt, something like:

      QProcess p;
      p.setOutputFile(log-file);
      p.start('sqlplus', QStringList() << "myUser/user_pwd@orcl" << "@path_to_script\\script_ora.sql");
      

      You will have to check the quote/backslash embedding, but these are the two ways of going about it to handle redirection.

      1 Reply Last reply
      1
      • M Offline
        M Offline
        mourad_bilog
        wrote on last edited by
        #3

        @JonB Many thanks for your helpful reply.

        But with the code below

        m_sCommandQuery = QString("sqlplus %1/%2@%3 @\"%4\\%5\" > %4\\exe_scrip.log ").arg(m_sDbUser, m_sDbPwd, m_sDbName, script_path.replace("/","\\"), script_name);
        
        		argList << "/c" << m_sCommandQuery;
        
        		process->start("cmd", argList);
        		process->waitForStarted();
        		process->waitForFinished();
        
        		process->close();
        

        I've the following error

        Process finished ==> Error :  'sqlplus' n'est pas reconnu en tant que commande interne
        ou externe, un programme ex?cutable ou un fichier de commandes.
        

        Note that the path of oracle bin is present in the enviroment variables.

        Can you tell me what wrong ?

        For the second approch, I've implemented as following

        process->setStandardOutputFile(QString("%1\\exec_script_%2.log").arg(script_path.replace("/","\\"), script_name));
        		argList.clear();
        		argList << QString("%1/%2@%3 @\"%4\\%5\"").arg(m_sDbUser, m_sDbPwd, m_sDbName, script_path.replace("/","\\"), script_name);
        		process->startDetached("sqlplus", argList);
        		process->waitForStarted();
        		process->waitForFinished();
        

        but no log file was created.

        Can you tell me what wrong and how to fix this.

        Really many thanks.
        Regards.

        JonBJ 1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          For your tests, you should use the full path to the executable. You can check after that the state of the PATH environment variable.

          For your paths, use forward slashes in your code and then QDir::toNativeSeparators. That will make things easier to write.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • M mourad_bilog

            @JonB Many thanks for your helpful reply.

            But with the code below

            m_sCommandQuery = QString("sqlplus %1/%2@%3 @\"%4\\%5\" > %4\\exe_scrip.log ").arg(m_sDbUser, m_sDbPwd, m_sDbName, script_path.replace("/","\\"), script_name);
            
            		argList << "/c" << m_sCommandQuery;
            
            		process->start("cmd", argList);
            		process->waitForStarted();
            		process->waitForFinished();
            
            		process->close();
            

            I've the following error

            Process finished ==> Error :  'sqlplus' n'est pas reconnu en tant que commande interne
            ou externe, un programme ex?cutable ou un fichier de commandes.
            

            Note that the path of oracle bin is present in the enviroment variables.

            Can you tell me what wrong ?

            For the second approch, I've implemented as following

            process->setStandardOutputFile(QString("%1\\exec_script_%2.log").arg(script_path.replace("/","\\"), script_name));
            		argList.clear();
            		argList << QString("%1/%2@%3 @\"%4\\%5\"").arg(m_sDbUser, m_sDbPwd, m_sDbName, script_path.replace("/","\\"), script_name);
            		process->startDetached("sqlplus", argList);
            		process->waitForStarted();
            		process->waitForFinished();
            

            but no log file was created.

            Can you tell me what wrong and how to fix this.

            Really many thanks.
            Regards.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @mourad_bilog
            Do all things @SGaist says. I don't think startDetached() is right, it may interfere with either redirection or certainly waitForFinished() I would have thought. Test your stuff a bit at a time. The principle of redirection does work.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mourad_bilog
              wrote on last edited by
              #6

              Hello,
              Many thanks @SGaist, @JonB for your contribution and very helpfull responses.

              now, the output log is ok. I've juste one thing to resolve. In fact, when running sqlplus without to full path, I've an error that this file is not found or not existing noting that the oracle bin path is indicated in the envirement path.
              Can you tell me why I've this error and what I must to change to fix this problem.

              Many thanks in advance.
              Regards.

              JonBJ 1 Reply Last reply
              0
              • M mourad_bilog

                Hello,
                Many thanks @SGaist, @JonB for your contribution and very helpfull responses.

                now, the output log is ok. I've juste one thing to resolve. In fact, when running sqlplus without to full path, I've an error that this file is not found or not existing noting that the oracle bin path is indicated in the envirement path.
                Can you tell me why I've this error and what I must to change to fix this problem.

                Many thanks in advance.
                Regards.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @mourad_bilog
                How do you run this sqlplus completely outside of Qt?

                M 1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Check the PATH environment variable in the Run part of the Project panel. It likely does not contain the path to sqlplus.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • JonBJ JonB

                    @mourad_bilog
                    How do you run this sqlplus completely outside of Qt?

                    M Offline
                    M Offline
                    mourad_bilog
                    wrote on last edited by
                    #9

                    @JonB from the Windows bash I run direcly sqlplus without the full path.
                    Note that, if I test with the sqlcmd (SQL Server) from Qt application, it work fine without the full path.

                    Note that twice pathes are in variables envirenement

                    JonBJ 1 Reply Last reply
                    0
                    • M mourad_bilog

                      @JonB from the Windows bash I run direcly sqlplus without the full path.
                      Note that, if I test with the sqlcmd (SQL Server) from Qt application, it work fine without the full path.

                      Note that twice pathes are in variables envirenement

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #10

                      @mourad_bilog
                      What directory is the sqlplus in? How does your PATH variable outside of Qt ()"from the Windows bash I run direcly sqlplus" compare to the PATH when launching your process from within Creator or wherever you run it from? When it does not work via QProcess, what have you done about checking for any error and in particular reporting any process->readAllStandardError() (and readAllStandardOutput())?

                      M 1 Reply Last reply
                      0
                      • JonBJ JonB

                        @mourad_bilog
                        What directory is the sqlplus in? How does your PATH variable outside of Qt ()"from the Windows bash I run direcly sqlplus" compare to the PATH when launching your process from within Creator or wherever you run it from? When it does not work via QProcess, what have you done about checking for any error and in particular reporting any process->readAllStandardError() (and readAllStandardOutput())?

                        M Offline
                        M Offline
                        mourad_bilog
                        wrote on last edited by
                        #11

                        @JonB sqplus is located in

                         D:\app1\Mouadh\product\11.2.0\dbhome_2\BIN
                        

                        Here's the %PATH% output from the Windows command bash :

                        echo %PATH%
                        D:\app1\Mouadh\product\11.2.0\dbhome_2\bin;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Java\jdk1.7.0_09\bin;C:\Program Files (x86)\Java\jre7\bin;C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;
                        

                        I'm using MS Vistual Studio and readAllStandardError() (and readAllStandardOutput() return the error "not found or not internal /external / batch command" when I call qprocess start.

                        JonBJ 1 Reply Last reply
                        0
                        • M mourad_bilog

                          @JonB sqplus is located in

                           D:\app1\Mouadh\product\11.2.0\dbhome_2\BIN
                          

                          Here's the %PATH% output from the Windows command bash :

                          echo %PATH%
                          D:\app1\Mouadh\product\11.2.0\dbhome_2\bin;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Java\jdk1.7.0_09\bin;C:\Program Files (x86)\Java\jre7\bin;C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;
                          

                          I'm using MS Vistual Studio and readAllStandardError() (and readAllStandardOutput() return the error "not found or not internal /external / batch command" when I call qprocess start.

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by
                          #12

                          @mourad_bilog
                          So you can see it is finding it from the very first element in your PATH when you execute from " the Windows command bash". I don't know when/where that gets prepended to your PATH? It appears to be the case that your PATH does not have that when you execute it from Creator. @SGaist told you:

                          Check the PATH environment variable in the Run part of the Project panel. It likely does not contain the path to sqlplus.

                          ? Maybe it gets prepended only when you go into bash shell, e.g. some Windows .bashrc file. So either you have do the same/run it via bash as I showed earlier, or you have to put the necessary into that variable in Creator. Also depends whether your application is for your own use only or whether you intend to distribute it to others.

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved