In shake-build, how to run a command with a pipe in it? - shake-build-system

I can't seem to get the following to work in shake:
cmd_ (AddEnv "PGPASSWORD" "REDACTED") "bzcat /tmp/db.sql.bz2 | psql -U pguser -h localhost dbname"

In Shake, the cmd function and variants spawn processes directly by default. The pipe syntax is only available as part of the OS's shell functionality. To ask Shake to spawn things using the shell add the argument Shell.

Related

How can I answer a command that needs input in Plink?

I run a command in Linux remote machine using plink (from batch file in Windows).
For example:
plink.exe -ssh root#IP -pw pass -m testCommands.txt >> uninstall.log
In testCommands.txt I have a command that perform uninstall of application,
the problem is that command of "uninstall" require an answer (y or n),
How can I send answer in addition to what I already send?
Here is the question I have:
[?7hAre you sure you want to completely remove "APPLICATION" and all of its components?
Yes [y, Enter], No [n]"
There are several options...
Use a -y or auto-confirm option on the command that removes the software, e.g.
pkg rm -yes somePackacge
Use a pipe to send the yes, so that the command you run in PLINK looks like
printf "Yes\n" | pkg rm some_package
or
yes | pkg rm some_package
Make the command that you run on the Linux machine be based on expect which can spawn your remove command, wait for a question and then send it a confirmation. Some expect examples here.

When I run a GDB/MI session with a command file, can the commands in the command file be parsed as MI commands?

I use ngdbmi (a node.js package, which spawns a GDB/MI child process) to control GDB, but sometimes GDB throws a timeout error, and the rsp log is completely worthless.
I doubt that ngdbmi or GDB/MI has bugs, so I first tested GDB/MI and wrote a command file to test GDB/MI, like:
$ sparc-rtems-gdb -i mi -x command_file
The test passes, but I have a question:
The command file consists of commands like target remote: 65535, not commands like -target-select remote localhost: 65535 (I tried this, but gdb/mi -x command_file doesn't identify). Therefore, I can't determine whether when running sparc-rtems-gdb -i mi -x command_file, GDB will parse commands to MI commands, or just perform commands as UI commands. (I doubted gdb/mi has bugs, gdb/ui is ok, but now I'm not sure.)

Use of su command in c code

I want to use a command in my c code. This command works properly when i am a superuser in terminal (using su) but does not work when I use sudo. I gathered that I can use system() in my c code as follows
system("su -c \"mycommand\"")
myCommand is a command that sends input to some device, like (echo 1 > mydevice)
I compiled my c code using gcc and run the output file. The trouble is, it wants root password from terminal when it comes to this line.
Is there a way I supply password programatically? I did it before with sudo command with -S option, but sudo command does not work for this case. If it is not possible, is there another way to deal with this?
Try this instead,
system("sudo sh -c \"mycommand\"");

Executing ssh command in c program using popen()

When I try executing this using popen it returns this error but when I run this in terminal it works!
popen("ssh -n -f *.*.*.* 'sshfs -o nonempty *.*.*.*:/home/foo/bar/ /foo1/foo2/foo3'", "r");
error:
ssh_exchange_identification: Connection closed by remote host
I use public and private key to ssh without passwords and they work properly as this command run flawlessly in terminal.
I changed it to this :
popen("ssh -n -f *.*.*.* `sshfs -o nonempty *.*.*.*:/home/foo/bar/ /foo1/foo2/foo3`", "r");
It return errors too.
error :
fuse: bad mount point `/foo1/foo2/foo3': No such file or directory
Cannot fork into background without a command to execute.
I also tried escipping the internal "" this way : \" \" but it hangs!
Replace ssh with /usr/bin/ssh, do the same with other commands, like sshfs. Specify the full path of the command, /usr/sbin/foo or whatever the case may be. popen does not necessarily use the same shell you have at the command line to execute commands. Check your documentation.

C program that executes bash commands inside xterm with execl

I have a command that execute well in the normal terminal on Linux:
xterm -e bash -c "some commands"
I want to execute the above command using c program execXX system calls. I try to use the following codes but it gives me a normal xterm window.
execl("/usr/bin/xterm", "/usr/bin/xterm -e bash -c \"some commands\"", NULL);
Is there any way I can execute the above command using execXX system calls? Thank you!
You need to call it like:
execl("/usr/bin/xterm", "/usr/bin/xterm", "-e", "bash", "-c", "some commands", (void*)NULL);
The convention is to let the first argument be the same as the path to the program. If you have spaces in the arguments, it will be the same effect as calling xterm 'something with spaces' instead of xterm something with spaces.
A possible tangent: is there any reason why you need these to run specifically within xterm? If you just want to run some shell commands, then running them within /bin/sh or /bin/bash would be more natural, and probably more reliable.

Resources