Ruby Command Line: How can I send the CTRL-C command through text on the command line?

I am trying to create a simple drop of Automator that will transfer a file into it style.lessand run the following LESS command:

$ LESSC {DROPPED_FILE} --watch

which will control the file that I ran for any changes, and then automatically update the output style.css

FYI: I use LESS to create dynamically written CSS files. More info here .

The main drop works fine.

  • The discarded file is passed to the variable; For this purpose: {MY_VAR}.
  • I run the shell script in the shell /usr/bin/rubyas followssystem("lessc {MY_VAR} --watch &")

this works fine, but I want -watch to be stopped after exiting the vending application.

The LESS documentation specifies the CTRL-C key combination, and the script terminates on the command line.

But since I am not in the terminal window (the command is transmitted in the background), I do not know how to interrupt the script.

Even after automator.app has been closed, the file style.lessis still scanned for changes, and the generated generated one style.cssis still overwritten.

So basically I need to pass the abort command when exiting .app.

I created a simple pop-up inscription that closes the application after clicking , transferring another command to the terminal shell.

This is the part where all my attempts failed to stop the script.

Is there a command line function that acts the same as pressing CTRL-C? How to convey this best for the shell?

+3
3

CTRL-C , STDIN . Bash ( , ) CTRL-C. bash . CTRL-C SIGINT. , . pid. pid, ruby.

p= IO.popen("lessc #{file} --watch")
pid= p.pid
Process.kill("INT", pid)

3 .

`lessc #{file} --watch` # returns stdout after exit
system("lessc #{file} --watch") # returns the integer return value after exit
Io.popen("lessc #{file} --watch") # returns imidietly an io object, where STDIN and STDOUT can be written and read

system("lessc #{file} --watch&"), imidietly, 0.

+6

: ^ C Control-C ?

( ).

: PDF . , ^ C. .

^ C , SIGINT , . Ruby. ( ) Ruby: http://whynotwiki.com/Ruby_/_Process_management.

.

+1
I think that

less also ends when it receives the character "q".

0
source

Source: https://habr.com/ru/post/1720948/


All Articles