What should I write in ofSystem() of OFX? - terminal

I am a mac users, I want to use youtube api to allow openframeworks load videos of youtube. So I use youtube-dl to download video in terminal. Then I found I can use ofSystem in OFX to execute terminal command.
My problem is I can execute youtube-dl in terminal that it does download video from youtube, but when I write this command into OFX, it just said that youtube-dl: command not found.
My code :
string link = https://www.youtube.com/watch?v=YPMeEfeBcPU;
string cmd = "youtube-dl " + link;
cout<<ofSystem(cmd.c_str());
Actually, when I just transfer this command into a normal terminal command like
string cmd = say Hello World!
This is works!
So I want to know what should I do.

Try to call the youtube-dlcommand with its full path. Something like:
string cmd = "/usr/local/bin/youtube-dl " + link;
Some more detail:
The ofSystem() will most likely call system() internally, which starts the command-argument in sh and not in the bash you are using in your terminal.
To verify this, open terminal and call sh. This will open a new shell prompt (sh shell). Now call youtube-dl and it will most likely not be found as well.

Related

passing a string to open command in mac

I want to pipe a string to the open command in zsh terminal.
this command: open https://www.google.com open the web-browser correctly.
However, running this command: echo https://www.google.com | open does not work. What's the correct way to pipe a string to this command?
As far as I can see from the Man Page the open command does not take input from stdin so piping into it does not make much sense, but your syntax for piping is correct. You probably want to pass the result of echo as an argument.
Try:
open $(echo https://www.google.com)

Ruby: How to open .exe file(that open CMD) and run command init

I am trying using ruby script to a task.
I have an .exe file that i want to run.
when opening this file it open in CMD and i can pass commands to it.
That file located in C:\temp\test.exe
I need to go to the directory and then open the file and then insert to it command like:
"getobject" task = "aa"
this program will give me the result to the CMD.
i will need to copy the result to text but i think i can handle it late.
I tried to search it online cant found anything.
Thanks
If you want to open an executable, usually you can use the `command` syntax in Ruby. So call:
`C:\temp\test.exe`
That should run the executable from the Ruby script. Then you can interact with that executable as if you ran it from a CMD instead of a Ruby file.
In order to run and capture the output of a command you'll need to use a system command. There are many system commands that you can use, but my preference is Open3:
require 'open3'
output, status = Open3.capture2("C:\temp\test.exe")
In the event that you want to pass command line arguments to capture2 you'll want to write that like this: Open3.capture2("C:\temp\test.exe", "arg1", "arg2"). That is the safest way to pass arguments.
I think what you are looking for is input/ output redirection
check redirection
Not tested
system 'C:\temp\test.exe < "\"getobject\" task = \"aa\""'

How to extract information from a command prompt using shell script?

I need a shell script using which I can fetch data from command prompt. I need to fetch data from the command prompt of a router. When I write commands in a shell script it goes the prompt but not executing the next command. So running the script just stuck in the prompt. Bellow is my script file
#!/bin/sh
ccli
rsc
where ccli is the command to enter the prompt and rsc is the command to fetch some infomation.
So please suggest some method.
If ccli reads commands from stdin (which I don't know), you might get further with
printf 'rsc\n' | ccli
For more complicated tasks I suggest you look into expect which was invented for the sole reason of driving interactive programs in a scripted way.

not found in shell to call expect

i've installed expect,and checked the path not wrong(which expect)
my shell program is to call the rsync,here's the source code
#!/usr/bin/expect -f
set timeout -1
spawn rsync -ravz /home/mypath username#remotehost:/data/
expect "*password:"
send "mypassowrd\r"
interact
save it as aaa.sh
run the file
sh aaa.sh
the terminal give result
: not foundaaa.sh:
aaa.sh: 4: aaa.sh: spawn: not found
": no such file or directoryd:
aaa.sh: 6: aaa.sh: send: not found
: not foundaaa.sh: interact
set it executable and run it by
./aaa.sh
give the result
": no such file or directory
have no idea why this happens,seems the expect wouldn't be call in shell file.
directly type expect is ok,but doesn't make sense.
I believe that is because you are trying to interpret expect commands with sh.
What I would do is the following. Save your script with the standard expect file extension .exp (this is just for clarity), make it an executable, and then just run it from your shell.
mv aaa.sh aaa.exp
chmod u+x aaa.exp
./aaa.exp
You have already let your script know where the expect binary is located, so that should be enough for you.
Let me know how that works out for you.

Running shell commands in GVim without echoing the Vim command

When I use :! to run shell commands, like:
!echo hi
It prints both the VimScript command and it's output, so I get:
:!echo hi
hi
This is OK when I do it in command line mode, but when I run it via a .vim file I don't want to see it - I just want to see the result of the command.
Is there a way to disable the echoing of the VimScript command?
I know I can use
echo system('echo hi')
But that would prevent me from using it with interactive shell programs...
BTW, I'm using Linux - in windows this is not really a problem since shell commands run on a new console window anyways...
edit:
This is my small working example:
function! RunShellTask(cmd)
execute '!'.a:cmd
return v:shell_error
endfunction
call RunShellTask('echo hi')
I run it with :source %
You could try the :redir command:
*:redi* *:redir*
:redi[r][!] > {file} Redirect messages to file {file}. The messages which
are the output of commands are written to that file,
until redirection ends. The messages are also still
shown on the screen. When [!] is included, an
:
:
To stop the messages and commands from being echoed to
the screen, put the commands in a function and call it
with ":silent call Function()".
An alternative is to use the 'verbosefile' option,
this can be used in combination with ":redir".
I haven't tested, but you could try :redir #b, execute the shell commands from a function called with :silent call, read the output (from register b), filter out the vimscript commands, display it on the screen and then :redir end.
Another option is to try some plugins that provide similar functionality:
shellasync.vim : shellasync.vim plugin for asynchronously executing shell commands in vim
Conque Shell : Run interactive commands inside a Vim buffer
Screen (vim + gnu screen/tmux) : Simulate a split shell, using gnu screen or tmux, that you can send commands to.
Vicle : Vim - Interpreter Command Line Editor. Like Chimp or Slimv.

Resources