multiline CMD in dockerfile what does it mean? - dockerfile

I saw this in some dockerfiles, what does it mean?
CMD ["phpcs"]
CMD ["phpcbf"]
without entrypoint.

CMD does not require an entrypoint, from the documentation:
The CMD instruction has three forms:
CMD ["executable","param1","param2"] (exec form, this is the preferred form)
CMD ["param1","param2"] (as default parameters to ENTRYPOINT)
CMD command param1 param2 (shell form)
Basically, you use the entrypoint if you omit the executable parameter. In these cases it's running phpcs and phpcbf without parameters.

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

Why is this ENTRYPOINT incorrect?

My DockerFile has an ENTRYPOINT that just echoes ENTRYPOINT echo %windir%\system32\inetsrv\appcmd to the command window.
This syntax works: ENTRYPOINT echo %windir%\system32\inetsrv\appcmd
This doesn't: ENTRYPOINT ["echo", "%windir%\system32\inetsrv\appcmd"]
The output is '[\"echo\"' is not recognized as an internal or external command, operable program or batch file.
What's the different between these two syntaxes?
The answer was in the documentation (who'd have thought that?)
The first form executes in a shell, and is therefore equivalent to anything you might type into it.
The second form doesn't execute in a shell, it just executes the file with the provided arguments.

QProcess can launch programs but not python (command line)

The following code is failing to launch the python command line.
QProcess *myProcess = new QProcess(this);
myProcess->start("\"C:\\Program Files\\Python27\\python.exe\"");
If I replace python27 with (for example)
myProcess->start("\"C:\\Program Files\\Notepad++\\notepad++.exe\"")
notepad opens. Why is my program able to launch notepad but not Python Command Line?
I tried using startDetached() as suggested here but that didn't make a difference.
QProcess::Error() gives me error 5: unknown error.
If you just want to use the 'python console' you must use cmd.exe application from windows
You must have python in PATH so the windows console will know where to take it from.
So, you can try: QProcess::startDetached("cmd", "python")..see more specific syntax details here
It seems I've misunderstood what happens when you launch a command line. I was expecting the python command line or command prompt window to open.
It turns out that if I just pass my commands as arguments start() like so:
myProcess->start("cmd.exe /C python C:\\Users\\SP4\\Desktop\\helloworld.py");
Command prompt runs my python script and I get the output ("Hello World") using:
QString output = myProcess->readAllStandardOutput();
All this happens in the background and you can't actually see a command line window open and print out "Hello, World".
Please correct me if I've misunderstood something.

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")

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")