# phpman > man > GPG-CONNECT-AGENT(1)

[GPG-CONNECT-AGENT(1)](https://www.chedong.com/phpMan.php/man/GPG-CONNECT-AGENT/1/markdown)                    GNU Privacy Guard 2.2                   [GPG-CONNECT-AGENT(1)](https://www.chedong.com/phpMan.php/man/GPG-CONNECT-AGENT/1/markdown)



## NAME
       **gpg-connect-agent** - Communicate with a running agent

## SYNOPSIS
       **gpg-connect-agent** [_options_]_[commands]_


## DESCRIPTION
       The  **gpg-connect-agent** is a utility to communicate with a running **gpg-agent**.  It is useful to
       check out the commands **gpg-agent** provides using the Assuan interface.  It might also be  use‐
       ful for scripting simple applications.  Input is expected at stdin and output gets printed to
       stdout.

       It is very similar to running **gpg-agent** in server mode; but here we connect to a running  in‐
       stance.




       The following options may be used:


### -v
### --verbose
              Output additional information while running.


### -q

### --quiet
              Try to be as quiet as possible.


       **--homedir** _dir_
              Set the name of the home directory to _dir_. If this option is not used, the home direc‐
              tory defaults to ‘_~/.gnupg_’.  It is only recognized when given on  the  command  line.
              It  also  overrides  any  home  directory  stated  through  the  environment  variable
              ‘_GNUPGHOME_’ or (on  Windows  systems)  by  means  of  the  Registry  entry  _HKCU\Soft__‐
              _ware\GNU\GnuPG:HomeDir_.

              On Windows systems it is possible to install GnuPG as a portable application.  In this
              case only this command line option is considered, all other ways to set a home  direc‐
              tory are ignored.

              To  install  GnuPG as a portable application under Windows, create an empty file named
              ‘_gpgconf.ctl_’ in the same directory as the tool ‘_gpgconf.exe_’.  The root  of  the  in‐
              stallation  is  then  that directory; or, if ‘_gpgconf.exe_’ has been installed directly
              below a directory named ‘_bin_’, its parent directory.  You also need to make sure  that
              the  following  directories exist and are writable: ‘_ROOT/home_’ for the GnuPG home and
              ‘_ROOT/var/cache/gnupg_’ for internal cache files.


       **--agent-program** _file_
              Specify the agent program to be started if none is running.  The default value is  de‐
              termined  by  running  **gpgconf** with the option **--list-dirs**.  Note that the pipe symbol
              (**|**) is used for a regression test suite hack and may thus not  be  used  in  the  file
              name.


       **--dirmngr-program** _file_
              Specify the directory manager (keyserver client) program to be started if none is run‐
              ning.  This has only an effect if used together with the option **--dirmngr**.


### --dirmngr
              Connect to a running directory manager (keyserver client) instead of to the gpg-agent.
              If a dirmngr is not running, start it.


### -S
       **--raw-socket** _name_
              Connect  to  socket _name_ assuming this is an Assuan style server.  Do not run any spe‐
              cial initializations or environment checks.  This may be used to directly  connect  to
              any Assuan style socket server.


### -E
       **--exec** Take the rest of the command line as a program and it's arguments and execute it as an
              Assuan server. Here is how you would run **gpgsm**:
          gpg-connect-agent --exec gpgsm --server
       Note that you may not use options on the command line in this case.


### --no-ext-connect
              When using **-S** or **--exec**, **gpg-connect-agent** connects to the Assuan server  in  extended
              mode to allow descriptor passing.  This option makes it use the old mode.


### --no-autostart
              Do not start the gpg-agent or the dirmngr if it has not yet been started.


### -r
       **--run** _file_
              Run the commands from _file_ at startup and then continue with the regular input method.
              Note, that commands given on the command line are executed after this file.


### -s
### --subst
              Run the command **/subst** at startup.


       **--hex**  Print data lines in a hex format and the ASCII representation of  non-control  charac‐
              ters.


### --decode
              Decode  data  lines.   That is to remove percent escapes but make sure that a new line
              always starts with a D and a space.


## CONTROL COMMANDS
       While reading Assuan commands, gpg-agent also allows a few special commands  to  control  its
       operation.  These control commands all start with a slash (**/**).



       **/echo** _args_
              Just print _args_.


       **/let** _name_ _value_
              Set  the  variable  _name_ to _value_.  Variables are only substituted on the input if the
              **/subst** has been used.  Variables are referenced by prefixing the name  with  a  dollar
              sign  and optionally include the name in curly braces.  The rules for a valid name are
              identically to those of the standard bourne shell.  This is not yet enforced  but  may
              be  in  the future.  When used with curly braces no leading or trailing white space is
              allowed.

              If a variable is not found, it is searched in the environment and if found  copied  to
              the table of variables.

              Variable  functions  are  available:  The  name of the function must be followed by at
              least one space and the at least one argument.  The following functions are available:


              **get**    Return a value described by the argument.  Available arguments are:


                     **cwd**    The current working directory.

                     **homedir**
                            The gnupg homedir.

                     **sysconfdir**
                            GnuPG's system configuration directory.

                     **bindir** GnuPG's binary directory.

                     **libdir** GnuPG's library directory.

                     **libexecdir**
                            GnuPG's library directory for executable files.

                     **datadir**
                            GnuPG's data directory.

                     **serverpid**
                            The PID of the current server. Command **/serverpid** must have  been  given
                            to return a useful value.


              **unescape** _args_
                     Remove C-style escapes from _args_.  Note that **\0** and **\x00** terminate the returned
                     string implicitly.  The string to be converted are the entire  arguments  right
                     behind the delimiting space of the function name.


              **unpercent** _args_
              **unpercent+** _args_
                     Remove  percent  style escaping from _args_.  Note that **%00** terminates the string
                     implicitly.  The string to be converted are the entire arguments  right  behind
                     the delimiting space of the function name. **unpercent+** also maps plus signs to a
                     spaces.


              **percent** _args_
              **percent+** _args_
                     Escape the _args_ using percent style escaping.  Tabs, formfeeds, linefeeds, car‐
                     riage returns and colons are escaped. **percent+** also maps spaces to plus signs.


              **errcode** _arg_
              **errsource** _arg_
              **errstring** _arg_
                     Assume  _arg_  is  an integer and evaluate it using **strtol**.  Return the gpg-error
                     error code, error source or a formatted string with the error  code  and  error
                     source.



              **+**
              **-**
              *****
              **/**
              **%**      Evaluate  all  arguments as long integers using **strtol** and apply this operator.
                     A division by zero yields an empty string.


              **!**
              **|**
              **&**      Evaluate all arguments as long integers using **strtol** and apply the logical  op‐
                     erators NOT, OR or AND.  The NOT operator works on the last argument only.





       **/definq** _name_ _var_
              Use  content of the variable _var_ for inquiries with _name_.  _name_ may be an asterisk (*****)
              to match any inquiry.



       **/definqfile** _name_ _file_
              Use content of _file_ for inquiries with _name_.  _name_ may be an asterisk (*****) to match any
              inquiry.


       **/definqprog** _name_ _prog_
              Run  _prog_  for  inquiries matching _name_ and pass the entire line to it as command line
              arguments.


       **/datafile** _name_
              Write all data lines from the server to the file _name_.  The file is opened for writing
              and  created  if  it  does not exists.  An existing file is first truncated to 0.  The
              data written to the file fully decoded.  Using a single dash for _name_ writes  to  std‐
              out.  The file is kept open until a new file is set using this command or this command
              is used without an argument.


### /showdef
              Print all definitions


### /cleardef
              Delete all definitions


       **/sendfd** _file_ _mode_
              Open _file_ in _mode_ (which needs to be a valid **fopen** mode string) and send the file  de‐
              scriptor  to  the  server.  This is usually followed by a command like **INPUT** **FD** to set
              the input source for other commands.


### /recvfd
              Not yet implemented.


       **/open** _var_ _file_ [_mode_]
              Open _file_ and assign the file descriptor to _var_.  Warning: This command is  experimen‐
              tal and might change in future versions.


       **/close** _fd_
              Close  the file descriptor _fd_.  Warning: This command is experimental and might change
              in future versions.


### /showopen
              Show a list of open files.


### /serverpid
              Send the Assuan command **GETINFO** **pid** to the server and store the returned PID  for  in‐
              ternal purposes.


       **/sleep** Sleep for a second.


### /hex
       **/nohex** Same as the command line option **--hex**.


### /decode
### /nodecode
              Same as the command line option **--decode**.


### /subst
### /nosubst
              Enable  and disable variable substitution.  It defaults to disabled unless the command
              line option **--subst** has been used.  If /subst as been enabled once, leading whitespace
              is removed from input lines which makes scripts easier to read.


       **/while** _condition_
       **/end**   These commands provide a way for executing loops.  All lines between the **while** and the
              corresponding **end** are executed as long as the evaluation of _condition_  yields  a  non-
              zero  value or is the string **true** or **yes**.  The evaluation is done by passing _condition_
              to the **strtol** function.  Example:

           /subst
           /let i 3
           /while $i
             /echo loop counter is $i
             /let i ${- $i 1}
           /end


       **/if** _condition_
       **/end**   These commands provide a way for conditional execution.  All lines between the **if**  and
              the  corresponding  **end** are executed only if the evaluation of _condition_ yields a non-
              zero value or is the string **true** or **yes**.  The evaluation is done by passing  _condition_
              to the **strtol** function.


       **/run** _file_
              Run commands from _file_.


       **/bye**   Terminate the connection and the program.


       **/help**  Print a list of available control commands.


## SEE ALSO
       [**gpg-agent**(1)](https://www.chedong.com/phpMan.php/man/gpg-agent/1/markdown), [**scdaemon**(1)](https://www.chedong.com/phpMan.php/man/scdaemon/1/markdown)

       The  full  documentation  for  this tool is maintained as a Texinfo manual.  If GnuPG and the
       info program are properly installed at your site, the command

         info gnupg

       should give you access to the complete manual including a menu structure and an index.





GnuPG 2.2.27                                 2020-12-21                         [GPG-CONNECT-AGENT(1)](https://www.chedong.com/phpMan.php/man/GPG-CONNECT-AGENT/1/markdown)
