public string Run(string command, string resultPrefix, double timeoutInSeconds)
        {
            if (_process == null || _process.HasExited)
            {
                throw new InvalidOperationException("The Sikuli process is not running");
            }

            _asyncTwoWayStreamsHandler.WriteLine(command);
            _asyncTwoWayStreamsHandler.WriteLine("");
            _asyncTwoWayStreamsHandler.WriteLine("");

            string result = _asyncTwoWayStreamsHandler.ReadUntil(timeoutInSeconds, ErrorMarker, resultPrefix);

            if (result.IndexOf(ErrorMarker, StringComparison.Ordinal) > -1)
            {
                result = result + Environment.NewLine + string.Join(Environment.NewLine, _asyncTwoWayStreamsHandler.ReadUpToNow(0.1d));
                if (result.Contains("FindFailed"))
                {
                    throw new SikuliFindFailedException(result);
                }
                throw new SikuliException(result);
            }

            return(result);
        }
        public void Run(string command, double?timeoutInSeconds = 1)
        {
            if (_process == null || _process.HasExited)
            {
                throw new InvalidOperationException("The Sikuli process is not running");
            }

            _asyncStreamsHandler.WriteLine(command);
            _asyncStreamsHandler.WriteLine(string.Empty);
            _asyncStreamsHandler.WriteLine(string.Empty);

            var result = _asyncStreamsHandler.ReadUntil((double)timeoutInSeconds, Constants.ErrorMarker, Constants.ResultPrefix);

            if (result.IndexOf(Constants.ErrorMarker, StringComparison.Ordinal) <= -1)
            {
                return;
            }

            result = result + Environment.NewLine + string.Join(Environment.NewLine, _asyncStreamsHandler.ReadUpToNow(0.1d));

            if (!result.Contains("FindFailed"))
            {
                throw new ImageRecognitionException(result);
            }

            var regex = new Regex("FindFailed: .+");

            throw new ImageRecognitionFindFailedException(regex.Match(result).Value);
        }
        public void Start()
        {
            if (_process != null)
            {
                throw new InvalidOperationException("This Sikuli session has already been started");
            }

            _process             = _imageRecognitionService.Start("-i");
            _asyncStreamsHandler = new AsyncStreamsHandler(_process.StandardOutput, _process.StandardError, _process.StandardInput);
            _asyncStreamsHandler.ReadUntil(Constants.SikuliReadyTimeoutSeconds, Constants.InteractiveConsoleReadyMarker);
        }
        public void Start()
        {
            if (_process != null)
            {
                throw new InvalidOperationException("This Sikuli session has already been started");
            }

            _process = _sikuliScriptProcessFactory.Start("-i");

            _asyncTwoWayStreamsHandler = _asyncDuplexStreamsHandlerFactory.Create(_process.StandardOutput, _process.StandardError, _process.StandardInput);
            _asyncTwoWayStreamsHandler.ReadUntil(SikuliReadyTimeoutSeconds, InteractiveConsoleReadyMarker);
        }