Class: AssLauncher::Support::Shell::Command Private

Inherits:
Object
  • Object
show all
Defined in:
lib/ass_launcher/support/shell.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Note:

What reason for it? Reason for it:

Fucking 1C binary often unexpected parse cmd arguments if run in shell like ‘1c.exe arguments`. For correction this invented two way run 1C binary: as command see Command or as script see Script. If run 1C as command we can control executing process wait exit or kill 1C binary process. If run 1C as script 1C more correctly parse arguments but we can’t kill subprosess running in cmd.exe

Note:

On default use silient execute 1C binary whit /DisableStartupDialogs, /DisableStartupMessages parameters and capture 1C output /OUT parameter. Read message from /OUT when 1C binary process exit and build instnce of RunAssResult.

Note:

Fucking 1C not work with stdout and stderr For out 1C use /OUT“file” parameter and write message into. Message encoding ‘cp1251’ for windows and ‘utf-8’ for Linux

Command running directly as: popen3(command.cmd, *command.args, options)

Direct Known Subclasses

Script

Constant Summary collapse

DEFAULT_OPTIONS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{ silent_mode: true,
capture_assout: true,
disable_auto_check_version: true}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd, args = [], options = {}) ⇒ Command

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Command.

Parameters:

  • cmd (String)

    path to 1C binary

  • args (Array) (defaults to: [])

    arguments for 1C binary

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :assout_encoding (String)

    encoding for assoutput file. Default ‘cp1251’

  • :capture_assout (Boolean)

    capture assoutput. Default true

  • :silent_mode (Boolean)

    run 1C with /DisableStartupDialogs and /DisableStartupMessages parameters. Default true

Raises:

  • (ArgumentError)

    when capture_assout: true and args include /OUT parameter



120
121
122
123
124
125
126
127
# File 'lib/ass_launcher/support/shell.rb', line 120

def initialize(cmd, args = [], options = {})
  @options = DEFAULT_OPTIONS.merge(options).freeze
  @cmd = cmd
  @args = args
  validate_args
  @args += (_silent_mode + _disable_auto_check_version)
  @ass_out_file = _ass_out_file
end

Instance Attribute Details

#argsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



101
102
103
# File 'lib/ass_launcher/support/shell.rb', line 101

def args
  @args
end

#cmdObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



101
102
103
# File 'lib/ass_launcher/support/shell.rb', line 101

def cmd
  @cmd
end

#optionsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



101
102
103
# File 'lib/ass_launcher/support/shell.rb', line 101

def options
  @options
end

#process_holderObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



102
103
104
# File 'lib/ass_launcher/support/shell.rb', line 102

def process_holder
  @process_holder
end

Instance Method Details

#capture_assout?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


147
148
149
# File 'lib/ass_launcher/support/shell.rb', line 147

def capture_assout?
  options[:capture_assout]
end

#exit_handling(exitstatus, out, err) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



203
204
205
206
# File 'lib/ass_launcher/support/shell.rb', line 203

def exit_handling(exitstatus, out, err)
  RunAssResult.new(exitstatus, encode_out(out),
                   encode_out(err), ass_out_file.read)
end

#run(options = {}) ⇒ ProcessHolder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Run command

Parameters:

  • options (Hash) (defaults to: {})

    options for Process.spawn

Returns:



159
160
161
162
# File 'lib/ass_launcher/support/shell.rb', line 159

def run(options = {})
  return process_holder if running?
  ProcessHolder.run(self, options)
end

#running?true

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns if command was already running.

Returns:

  • (true)

    if command was already running



152
153
154
# File 'lib/ass_launcher/support/shell.rb', line 152

def running?
  !process_holder.nil?
end

#to_sObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



199
200
201
# File 'lib/ass_launcher/support/shell.rb', line 199

def to_s
  "#{cmd} #{args.join(' ')}"
end