can a "hook" execute a shell command in mutt? - mutt

Is there any way to have a "hook" execute a shell command? Either through a:
-
- tick marks (``)
- through "a macro"
I checked the neomutt documentation and it says that the hook command can execute something with backticks:
shutdown-hook 'echo `mbsync -a`'
But whenever I do that, I get:
echo: unknown command
I tried doing a:
shutdown-hook 'echo `ls`'
and I still get the same error. Am I missing something?

Did you place these commands in your .muttrc file?
This does work for me, inserting in .muttrc file
startup-hook 'echo `echo did it > /tmp/mutt-did-it`'
then running mutt, the file /tmp/mutt-did-it then contains did it. It does also work with folder and send hooks.

Related

gdb - how to make it call a program with a relative name [duplicate]

I am trying to launch a legacy application in GDB, and it requires that it's argv[0] value not contain anything other than alphanumeric characters.
Whenever I launch the program in GDB it seems that it expands the name to be the full path before running the program, so I get an error like (because it can't deal with the slashes):
"Cannot find /home/user/myapp ..."
Is it possible to run a program in GDB with a relative path, so that it will just see "myapp"?
Gdb normally runs target commands using the shell command line
exec program_pathname program_arguments
But it has a set exec-wrapper command that will change this to
exec exec_wrapper program_pathname program_arguments
The exec_wrapper is often another command, but it can be an option that the exec command accepts.
Many shells (bash, zsh, ksh93) support a -a option to the exec command to set argv[0].
So, if your shell supports exec -a, you can do the following to invoke /home/user/myapp with argv[0]==myapp:
(gdb) set exec-wrapper -a myapp

sbt-docker cannot run echo pipe

I am using sbt-docker and trying to setup ssh on docker by following this link: https://docs.docker.com/examples/running_ssh_service/.
sbt-docker seems not to understand below:
run("echo", "'root:root' | chpasswd")
Instead of changing the root user password, this run command simply prints string "'root:root' | chpasswd".
Similarly,
run("echo", "root:root", "&>", "rootpasswd.txt")
This command print "root:root &> rootpasswd.txt" instead of writing "root:root" into rootpasswd.txt file.
Any idea how to make sbt-docker correctly execute these echo commands? Thanks!
Docker can run commands in 2 ways, shell form and exec form. The shell form will run your command in a shell.
sbt-docker supports both formats with the methods: run (exec) and runShell (shell).
Since you are using a pipe you need to run your command using a shell. This is what the runShell method is for:
runShell("echo", "root:root", "|", "chpasswd")
runShell("echo", "root:root", "&>", "rootpasswd.txt")
You can also use the runRaw method, which allowes you to freely use any form:
runRaw("echo root:root | chpasswd")
runRaw("echo root:root &> rootpasswd.txt")

What is the difference between calling a script from the shell and using system()?

I have built a bash script to start up some processes in my system. It simply calls the process and associated config file. Same as I would call from the command line.
#!/bin/bash
# Start specified process in a new session
setsid $1 &>/dev/null &
So to start up someprocess, I would call from the command line:
root#supercomputer:~# start someprocess
This works like a charm. Every process, every time. But when I make a system call from a different running C++ process, someprocess never starts up.
system( "start someprocess" )
This approach for 90% of my processes, except for one. The only difference in the working and not working processes is that the non-working one uses proprietary libraries underneath. I recently added the setsid option to the bash script in hopes that starting a new session would help, but it made no difference. I've also tried popen, and execv. No change.
So my question is what is the difference between calling something with system() and just making that same call from the command line?
All processes are written in C++ on Linux.
.bashrc is only invoked if bash is run as interactive, non-login shell. If it's invoked as non-interactive shell, as when using system() on a script with a bash shebang, it only reads the configuration file pointed to by $BASH_ENV.
That means you have the following options:
add -l to the shebang - causes the shell to read ~/.profile at startup
set $BASH_ENV to the script you want sourced before calling system()
add -i to the shebang - invokes bash as interactive shell and causes it to read ~/.bashrc, but will also effect how bash handles input/output.
I'd recommend the first option.
You can find a detailed explanation of how bash reads it's startup files here. I'm not sure this will solve your problem completely, but it may at leas shed some light on that part of the issue.
Check the environment variables that are used in the system() call. For example, call system to print out some of the variables, and see if they match what you see from the command line.
Likely they are not being sourced correctly.

Execute shell command in c++

I have a question regarding executing shell commands in c++. I'm building an application in winforms, vs 2008. My application has a button, when clicked should decode a binary file to a .csv file. I can decode files by first going to the right directory (cd Test_Copy2) and then execute a command in the command prompt (java -jar tool.jar -b x.fit x.csv). I tried a lot of different stuff but unfortunately got none to work!
I tried using:
system, _popen, ShellExecute(NULL, L"open", L"C:\\WINDOWS\\system32\\cmd.exe ", L"java -jar Tool.jar -b x.fit x.csv", L"C:\\Test_Copy2", SW_SHOWNORMAL)
Can anyone please provide me with an example on how to do that? I dont know where I'm going wrong, most of the time the command prompt opens but no command is executed!
If you really want to run the jar in a cmd.exe instance, you need to add one of the correct command line switches to cmd.exe for it to work the way you want it to:
/C Carries out the command specified by string and then terminates
/K Carries out the command specified by string but remains
For instance, your command string should be:
C:\\WINDOWS\\system32\\cmd.exe /c java -jar Tool.jar -b x.fit x.csv
You can use the system() function to execute shell commands.
For example:
system("DIR") executes the DIR command in the CMD shell. The default directory at the start is the directory you're .exe file is located.
'system("PAUSE")` executes the PAUSE command.
The command/s you wannt to execute should be passed as a constant string to the function.
Edit:
For you paritcular program the syntax (IMO) would be:
system("java -jar Tool.jar -b x.fit x.csv")

Applescript waiting for close (I'd like it not to)

In Applescript, I have the following:
do shell script "/Applications/Vidalia.app/Contents/MacOS/Vidalia"
do shell script "/Applications/Firefox_3.6/Firefox.app/Contents/MacOS/firefox-bin -P Anon"
It works perfectly, but the issue is that it will wait for Vidalia to be CLOSED before it will then launch Firefox. I would like to open both at the same time with one script. I don't really understand the language and all of my searching has turned up nothing. How can I get these open simultaneously? That is the point, after all.
Any help is much appreciated.
Try using the open command to launch the applications:
do shell script "open /Applications/Vidalia.app"
do shell script "open /Applications/Firefox_3.6/Firefox.app --args -P Anon"
With do shell script, AppleScript will wait for the response of the process you're running. As you're calling it, there's no option but to wait for the process to terminate, which is when the application closes.
To solve this, you need to replace your shell commands with ones that provide no response and terminate right away. So try this:
do shell script "/Applications/Vidalia.app/Contents/MacOS/Vidalia &> /dev/null & /Applications/Firefox_3.6/Firefox.app/Contents/MacOS/firefox-bin -P Anon &> /dev/null &"
I didn't test this with the applications you're using, as I have neither installed; instead, I tested with iTunes and Bento, with which it worked as you're hoping.