12 Replies Latest reply on Jan 20, 2018 4:24 PM by Kukurykus

    Fast and invisible cmd call

    littlehorse3 Level 1

      I need to call cmd command to get HDD serial. I will do it often so I need fast and invisible (without popup console window) solution.

       

      1. app.system

      This is perfect fast and invisible solution on MacOS. But user see popup console window on Windows

      I will glad to know how to disable with popups windows. Do anybody know how?

       

      1. quiet VBs file creation and launching:

       

      var command="ping google.com";

      var vbsFile = File(Folder.temp + '/aps_call.vbs');

      vbsFile.open('w');

      //vbsFile.write("chcp 1251\r\n");

      vbsFile.write("Dim objShell\r\n");

      vbsFile.write('Set objShell = WScript.CreateObject( "WScript.Shell" )\r\n');

      vbsFile.write('objShell.Run "' + command + ' > ""' + decodeURI(tempFile.fsName) + '""", 0, True\r\n');

      vbsFile.write('Set objShell = Nothing\r\n');

      vbsFile.close();

       

      vbsFile.execute();

      $.sleep (200);

       

      This is invisible but very slow solution. I don't know why execute method takes 2-3 seconds on my pc. May be somebody knows how do it faster.. )

       

      Thanks for your attention and answers!

        • 1. Re: Fast and invisible cmd call
          SuperMerlin Level 5

          Windows 64bit only!

          You could use Pauls modified External Lib example.

          Files are here..

          wikisend.com/download/806904

          Place both files in the preset/ scripts folder.

          The jsx gives a few basix examples, the system command will return data without opening a dos window.

          • 2. Re: Fast and invisible cmd call
            littlehorse3 Level 1

            Where can I find documentation for this? Is this library free?

            • 3. Re: Fast and invisible cmd call
              SuperMerlin Level 5

              Yes its free, the modified code can be found here.. Get Photoshop foreground color as RGB value

              The original code (SDK) can be downloaded from Adobe... Bridge Developer Center

              • 4. Re: Fast and invisible cmd call
                littlehorse3 Level 1

                Thank you! But what about Winx86? I need support it too

                • 5. Re: Fast and invisible cmd call
                  SuperMerlin Level 5

                  Just recompile it then

                  • 6. Re: Fast and invisible cmd call
                    SuperMerlin Level 5

                    Just compiled a 32bit version for you...

                    Wikisend: free file sharing service

                    • 7. Re: Fast and invisible cmd call
                      littlehorse3 Level 1

                      OK. I will try to use it. Thank you again

                      • 8. Re: Fast and invisible cmd call
                        littlehorse3 Level 1

                        Sorry but .systemCmd shows cmd window. And I didn't find 'systemCmd' in documentation. May be it has more parameters..

                        Also I tries to use x86 version on x64 Windows and I got error of 'input-output'. Is it mean that I have to check WIndows type and have 2 libraries?

                        • 9. Re: Fast and invisible cmd call
                          SuperMerlin Level 5

                          The documentation is the code itself, you might be able to amend it to suit your needs, maybe you could use CreateProcess instead of popen?

                          • 10. Re: Fast and invisible cmd call
                            littlehorse3 Level 1

                            Yes it will be nice to use CreateProcess but sorry I'm still  don't see modified code of this library. For example code of systemCmd. Can you send me project that you complied or link of it?

                            • 11. Re: Fast and invisible cmd call
                              SuperMerlin Level 5

                              The modified code....

                               

                              #include "BasicExternalObject.h"
                              #include "SoSharedLibDefs.h"
                              #include <string>
                              #include <windows.h>
                              #include <stdio.h>
                              #include <iostream>
                              
                              #if defined (_WINDOWS)
                                  #pragma warning(disable : 4996) // Turn off warning about deprecated strcpy on Win
                              #endif
                              
                              /**
                              * \brief To allow string manipulation
                              */
                              using namespace std;
                              
                              /**
                              * \brief Utility function to handle strings and memory clean up
                              *
                              * \param s - The referenced string
                              */
                              static char* getNewBuffer(string& s)
                              {
                                  // Dynamically allocate memory buffer to hold the string 
                                  // to pass back to JavaScript
                                  char* buff = new char[1+s.length()];
                                  
                                  memset(buff, 0, s.length()+1);
                                  strcpy(buff, s.c_str());
                              
                                  return buff;
                              }
                              
                              
                              extern "C" BASICEXTERNALOBJECT_API long systemCmd(TaggedData* argv, long argc, TaggedData* retval)
                              {
                                  // The returned value type
                                  retval->type = kTypeString;    
                                  // Accept 1 and only 1 argument
                                  if(argc != 1)
                                  {
                                      return kESErrBadArgumentList;
                                  }
                              
                                  // The argument must be a string
                                  if(argv[0].type != kTypeString)
                                  {
                                      return kESErrBadArgumentList;
                                  }
                              
                              char*  cmd = (argv[0].data.string); 
                                  FILE* pipe = _popen(cmd, "r");
                                  if (!pipe) retval->data.string = "";
                                  char buffer[128];
                                  std::string result = "";
                                  while(!feof(pipe)) {
                                      if(fgets(buffer, 128, pipe) != NULL)
                                          result += buffer;
                                  }
                                  _pclose(pipe);
                                  retval->data.string = getNewBuffer(result);
                                  return kESErrOK;
                              }
                              extern "C" BASICEXTERNALOBJECT_API long getClipboard(TaggedData* argv, long argc, TaggedData* retval)
                              {
                                  // The returned value type
                                  retval->type = kTypeString;    
                                  HANDLE h;   
                                if (!OpenClipboard(NULL)) return kESErrBadArgumentList;  
                                h = GetClipboardData(CF_TEXT);
                                CloseClipboard();
                                if(h){
                                string text;
                                  text = (char*)h;
                                  if(text.length() < 1) return kESErrBadArgumentList;
                                  retval->data.string = getNewBuffer(text);
                                }else{
                              retval->data.string = "";
                                }
                                  return kESErrOK;
                              }
                              extern "C" BASICEXTERNALOBJECT_API long clearClipboard(TaggedData* argv, long argc, TaggedData* retval)
                              {
                                  if (OpenClipboard(NULL)){
                                      EmptyClipboard();
                                      CloseClipboard();
                                  }
                                  return kESErrOK;
                              }
                              extern "C" BASICEXTERNALOBJECT_API long setClipboard(TaggedData* argv, long argc, TaggedData * retval)
                              {    
                                  // Accept 1 and only 1 argument
                                  if(argc != 1)
                                  {
                                      return kESErrBadArgumentList;
                                  }
                              
                                  // The argument must be a string
                                  if(argv[0].type != kTypeString)
                                  {
                                      return kESErrBadArgumentList;
                                  }
                              
                              string source = (argv[0].data.string); 
                              int len = source.length() +1;
                              source = source.c_str();
                              if(OpenClipboard(NULL))
                              {
                                  HGLOBAL clipbuffer;
                                  char * buffer;
                                  EmptyClipboard();
                                  clipbuffer = GlobalAlloc(GMEM_DDESHARE, len);
                                  buffer = (char*)GlobalLock(clipbuffer);
                                  strcpy(buffer, LPCSTR(source.c_str()));
                                  GlobalUnlock(clipbuffer);
                                  SetClipboardData(CF_TEXT,clipbuffer);
                                  CloseClipboard();
                              }
                              
                                  return kESErrOK;
                              }
                              /**
                              * \brief Free any string memory which has been returned as function result.
                              *
                              * \param *p Pointer to the string
                              */
                              BASICEXTERNALOBJECT_API void ESFreeMem (void* p)
                              { 
                                  delete(char*)(p);
                              }
                              
                              /**
                              * \brief Returns the version number of the library
                              *
                              * ExtendScript publishes this number as the version property of the object 
                              * created by new ExternalObject.
                              */
                              BASICEXTERNALOBJECT_API long ESGetVersion()
                              {
                                  return 0x1;
                              }
                              
                              /**
                              * \brief Initialize the library and return function signatures.
                              *
                              * These signatures have no effect on the arguments that can be passed to the functions.
                              * They are used by JavaScript to cast the arguments, and to populate the
                              * reflection interface.
                              */
                              BASICEXTERNALOBJECT_API char* ESInitialize (const TaggedData ** argv, long argc) 
                              { 
                                  return "makeArray,getAverage,appendString_s,myScript_a,acceptBoolean_b";
                              }
                              
                              /**
                              * \brief Terminate the library.
                              *
                              * Does any necessary clean up that is needed.
                              */
                              BASICEXTERNALOBJECT_API void ESTerminate()
                              {
                                  
                              }
                              
                              
                              
                              
                              
                              
                              
                              
                              
                              
                              
                              
                              
                              
                              
                              
                              
                              
                              
                              
                              • 12. Re: Fast and invisible cmd call
                                Kukurykus Adobe Community Professional

                                I used vbs and that didn't make 2 - 3 seconds delay: Re: UI: Remember last path entered