1

Yowsup-cli is a library that can allow you to send message to whatsapp users,once authenticated. By the coommand

yowsup-cli -a --interactive <PHONE_NUMBER_HERE> --wait --autoack --keepalive --config yowsup-master/src/yowsup-cli.config

I can interactively send or receive messages. Once executed the command you get a prompt like

MY_PHONE_NUMBER@s.whatsapp.net [27-12-2014 18:33]:THIS IS MY MESSAGE,TYPED ON MY PHONE. OPEN DOOR GARAGE Enter Message or command: (/available, /lastseen, /unavailable) I'm a totally beginner, but I would like to redirect this content that gets printed on terminal to a file,to further analyze it or to write a script that search into this file keyword as "OPEN GARAGE DOOR", so i could automate something. This file obviously has to sync with the program output,but I don't know how to do.

yowsup-cli -a --interactive <PHONE_NUMBER_HERE> --wait --autoack --keepalive --config yowsup-master/src/yowsup-cli.config > /path/to/my_file doesn't work

Running Ubuntu 12.04. I know yowsup is a python library, but i don't know this language. I'm beginning learniing C and I would like to do that in BASH, or if not possible in C. Thanks

Jacquelyn.Marquardt
  • 602
  • 2
  • 12
  • 30

1 Answers1

0

Pipe the output into tee instead of redirecting it into a file:

yowsup-cli -a --interactive <PHONE_NUMBER_HERE> --wait --autoack --keepalive --config yowsup-master/src/yowsup-cli.config 2>&1 | tee -a /path/to/my_file

The reason: With redirection you don't see the command's output which makes interacting with it hard. Piping into the tee command will echo all output the the terminal and append it to given file.

Interestingly, in your command line (using redirection) you can still type blindly or even according to the yowsup-cli ouptut you read in another terminal with:

tail -f /path/to/my_file

Tail with the -f option prints the last 10 lines of the file as well as any new ouptut from the yowsup-cli command.

doublehelix
  • 3,118
  • 1
  • 14
  • 10
  • You need to be more specific. Is my_file being created? What's it content? Do you see your command's output on the terminal? Also make sure your command indeed produces output (to do that run it without the redirection/pipe part, just as the first command in your question) – doublehelix Dec 27 '14 at 18:46
  • Yes the file is being created. Its content is nothing if I open it with gedit (ubuntu default text editor) also tail -f returns nothing. If in terminal i type a msg, this msg arrives to my phone. You were right when you said you can still type blindly. – Jacquelyn.Marquardt Dec 27 '14 at 19:08
  • OK, i have in mind of creating a program and i began searching how to do it months ago and discovered yowsup. I also tried with telegram. This method (tee) doesnt'work for whatsapp, i don't know why, but i've just tried with telegram-cli, a library for telegram and it works. so i'll focus my attention only on telegram. I consider this question answered, an i accept it. but i have another question which i will expose i another post. Can you help me? Now i want to being able of responding from pc to mobile, using a script. – Jacquelyn.Marquardt Dec 27 '14 at 19:35
  • With yowsup, it is easy. you just type $ yowsup-cli --send phone_number "This is a message sent from pc, by a script that i wrote, informing you room temperature is 20 celsius" --config ........" – Jacquelyn.Marquardt Dec 27 '14 at 19:37
  • but with telegram-cli it is different. REFERENCE https://github.com/vysheng/tg you type on terminal $ bin/telegram-cli -k tg-server.pub and you are presented with an interactive environment and i don't know how to script or automate how to send msg from computer – Jacquelyn.Marquardt Dec 27 '14 at 19:40
  • The file being created and empty means that your yowsup-cli command is not producing any output on stdout. Either it doesn't produce output or it's to stderr which you can catch with 2>&1 (I've updated my post). – doublehelix Dec 27 '14 at 20:58
  • For automating input to interactive commands (like telegram-cli) read the man page of the excellent "expect" command: http://linux.die.net/man/1/expect – doublehelix Dec 27 '14 at 20:59