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
}

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



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

def initialize(cmd, args = [], options = {})
  @options = DEFAULT_OPTIONS.merge(options).freeze
  @cmd = cmd
  @args = args
  validate_args
  @args += _silent_mode
  @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.



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

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.



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

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.



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

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.



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

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)


145
146
147
# File 'lib/ass_launcher/support/shell.rb', line 145

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.



192
193
194
195
# File 'lib/ass_launcher/support/shell.rb', line 192

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:



157
158
159
160
# File 'lib/ass_launcher/support/shell.rb', line 157

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



150
151
152
# File 'lib/ass_launcher/support/shell.rb', line 150

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.



188
189
190
# File 'lib/ass_launcher/support/shell.rb', line 188

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