Sfoglia il codice sorgente

HPCC-18183 Direct ESDL.exe errors to stderr

- Outputs all error messages to stderr
- Adds function to route ws err status to stderr

Signed-off-by: Rodrigo Pastrana <rodrigo.pastrana@lexisnexis.com>
Rodrigo Pastrana 6 anni fa
parent
commit
ac6fef5196

+ 1 - 1
tools/esdlcmd-xml/esdl2xml.cpp

@@ -75,7 +75,7 @@ void parseCommandLine(int argc, char* argv[], Esdl2Esxdl * cmd)
             }
             else
             {
-                fprintf(stdout, "Unknown option: %s\n", argv[i]);
+                fprintf(stderr, "Unknown option: %s\n", argv[i]);
                 usage(argv[0]);
             }
         }

+ 20 - 15
tools/esdlcmd/esdl-publish.cpp

@@ -146,10 +146,13 @@ public:
             return 1;
         }
 
+        StringBuffer message;
         if (optESDLService.length() > 0)
-            fprintf(stdout, "\nESDL Service: %s: %s\n", optESDLService.get(), resp->getStatus().getDescription());
+            message.setf("ESDL Service: %s: %s", optESDLService.get(), resp->getStatus().getDescription());
         else
-            fprintf(stdout, "\n%s\n", resp->getStatus().getDescription());
+            message.set(resp->getStatus().getDescription());
+
+        outputWsStatus(resp->getStatus().getCode(), message.str());
 
         return 0;
     }
@@ -291,7 +294,7 @@ public:
             return 1;
         }
 
-        fprintf(stdout, "\n %s.\n", resp->getStatus().getDescription());
+        outputWsStatus(resp->getStatus().getCode(), resp->getStatus().getDescription());
 
         return 0;
     }
@@ -465,7 +468,7 @@ public:
             return 1;
         }
 
-        fprintf(stdout, "\n %s.\n", resp->getStatus().getDescription());
+        outputWsStatus(resp->getStatus().getCode(), resp->getStatus().getDescription());
 
         return 0;
     }
@@ -570,7 +573,7 @@ public:
             return 1;
         }
 
-        fprintf(stdout, "\n %s.\n", resp->getStatus().getDescription());
+        outputWsStatus(resp->getStatus().getCode(), resp->getStatus().getDescription());
 
         return 0;
     }
@@ -831,7 +834,7 @@ public:
             return 1;
         }
 
-        fprintf(stdout, "\n %s.\n", resp->getStatus().getDescription());
+        outputWsStatus(resp->getStatus().getCode(), resp->getStatus().getDescription());
 
         return 0;
     }
@@ -956,7 +959,7 @@ public:
 
         if (getresp->getStatus().getCode()!=0)
         {
-            fprintf(stdout, "\n Failed to retrieve ESDL Binding configuration for %s: %s.\n", optBindingId.get(), getresp->getStatus().getDescription());
+            fprintf(stderr, "\n Failed to retrieve ESDL Binding configuration for %s: %s.\n", optBindingId.get(), getresp->getStatus().getDescription());
             return success;
         }
 
@@ -1001,19 +1004,19 @@ public:
                             success = 0;
                         }
                         else
-                            fprintf(stdout, "\nCould not unbound method %s from ESDL Binding %s: %s\n", optMethod.get(), optBindingId.get(), resp->getStatus().getDescription());
+                            fprintf(stderr, "\nCould not unbound method %s from ESDL Binding %s: %s\n", optMethod.get(), optBindingId.get(), resp->getStatus().getDescription());
                     }
                     else
-                        fprintf(stdout, "\n Could not remove Method %s from ESDL Binding %s configuration.\n", optMethod.get(), optBindingId.get());
+                        fprintf(stderr, "\n Could not remove Method %s from ESDL Binding %s configuration.\n", optMethod.get(), optBindingId.get());
                 }
                 else
-                    fprintf(stdout, "\n Method %s doesn't seem to be associated with ESDL Binding %s.\n", optMethod.get(), optBindingId.get());
+                    fprintf(stderr, "\n Method %s doesn't seem to be associated with ESDL Binding %s.\n", optMethod.get(), optBindingId.get());
             }
             else
-                fprintf(stdout, "\n Could not interpret configuration for ESDL Binding %s :  %s.\n", optBindingId.get(), currentconfig );
+                fprintf(stderr, "\n Could not interpret configuration for ESDL Binding %s :  %s.\n", optBindingId.get(), currentconfig );
         }
         else
-            fprintf(stdout, "\n Received empty configuration for ESDL Binding %s.\n", optBindingId.get());
+            fprintf(stderr, "\n Received empty configuration for ESDL Binding %s.\n", optBindingId.get());
 
         return success;
     }
@@ -1183,8 +1186,10 @@ class EsdlGetDefinitionCmd : public EsdlGetCmd
             if (definition.length()==0) //as of wsesdlconfig 1.4 getxmldef moves to definition/Interface
                 definition.set(resp->getDefinition().getInterface());
 
-            fprintf(stdout, "\n%s", definition.str());
-            fprintf(stdout, "\n%s.\n", resp->getStatus().getDescription());
+            if (definition.length()!=0)
+                fprintf(stdout, "\n%s", definition.str());
+
+            outputWsStatus(resp->getStatus().getCode(), resp->getStatus().getDescription());
 
             return 0;
         }
@@ -1230,7 +1235,7 @@ public:
         }
 
         fprintf(stdout, "\n%s", resp->getConfigXML());
-        fprintf(stdout, "\n%s.\n", resp->getStatus().getDescription());
+        outputWsStatus(resp->getStatus().getCode(), resp->getStatus().getDescription());
 
         return 0;
     }

+ 1 - 1
tools/esdlcmd/esdl2ecl.cpp

@@ -499,7 +499,7 @@ public:
         }
         catch(...)
         {
-            fprintf(stdout, "Error transforming Esdl to ECL file %s", filename);
+            fprintf(stderr, "Error transforming Esdl to ECL file %s", filename);
         }
     }
 

+ 4 - 0
tools/esdlcmd/esdlcmd_common.hpp

@@ -133,6 +133,10 @@ public:
             "   -v,--verbose                         Output additional tracing information\n"
         );
     }
+    virtual void outputWsStatus(int code, const char * message)
+    {
+        fprintf(code == 0 ? stdout : stderr, "\n %s.\n", message);
+    }
 public:
     bool optVerbose;
 };

+ 2 - 3
tools/esdlcomp/esdl_utils.cpp

@@ -61,11 +61,10 @@ void es_createDirectory(const char* dir)
 int es_createFile(const char* src, const char* ext)
 {
     char * path = es_changeext(src,ext);
-    //printf("Target: %s\n", path);
     int h = open(path,_O_WRONLY | _O_CREAT | _O_TRUNC | _O_TEXT  , _S_IREAD|_S_IWRITE);
     if (h==-1)
     {
-        printf("Could not open file for write: %s (current dir: %s)\n",path,getcwd(NULL,0));
+        fprintf(stderr, "Could not open file for write: %s (current dir: %s)\n",path,getcwd(NULL,0));
     }
     free(path);
     return h;
@@ -161,7 +160,7 @@ int es_createFile(const char* src, const char* tail, const char* ext)
     int h = open(path,_O_WRONLY | _O_CREAT | _O_TRUNC | _O_TEXT  , _S_IREAD|_S_IWRITE);
     if (h==-1)
     {
-        printf("Could not open file for write: %s (current dir: %s)\n",path,getcwd(NULL,0));
+        fprintf(stderr, "Could not open file for write: %s (current dir: %s)\n",path,getcwd(NULL,0));
     }
     free(path);
     return h;