I have been looking on information about exec cmd.exe, but I cannot find anything helpful. Can anyone explain to me the following code:
exec cmd.exe /c start /wait $buildLoc\\setup.exe /extract_all:C:/setup
Let's break it down:
exec cmd.exe /c start /wait $buildLoc\\setup.exe /extract_all:C:/setup
#^^^
The exec command starts a subprocess.
exec cmd.exe /c start /wait $buildLoc\\setup.exe /extract_all:C:/setup
# ^^^^^^^^^^
cmd.exe is a windows "batch" shell, The /c flag asks it to run its arguments as a command.
exec cmd.exe /c start /wait $buildLoc\\setup.exe /extract_all:C:/setup
# ^^^^^^^^^^^
The start command, built into cmd.exe, is also a way to get another program to start. The /wait flag tells it to wait until the started program ends.
exec cmd.exe /c start /wait $buildLoc\\setup.exe /extract_all:C:/setup
# ^^^^^^^^^
A regular TCL variable; it will be expanded inside TCL.
The rest is whatever the setup.exe program does (which is who knows what...)
Without knowing a little more about the program being run here (see below) it's hard to say exactly why the intermediate exec.cmd /c start /wait was needed; I'd guess that the cmd.exe is to load all of the system's default environment (instead of using the environment inherited from the tcl program) and the start is to open a terminal window so the output of the setup.exe program is shown to the user.
Check out auto_execok
exec {*}[auto_execok start] /wait $buildLoc\\setup.exe /extract_all:C:\\setup
Related
Recently, I tried to debug a cross compiled arm program with QEMU, but I got stuck with an issue.
This is the code, very simple.
int main()
{
printf("aaa\n");
int status;
status = system("./bin/ls");
printf("Result of [system] = 0x%x\n", status);
}
When I launch the program using command
spy#spy-virtual-machine:/usr/arm-linux-gnueabihf$ ./qemu-arm-static -L ./ ./a.out
The output is:
aaa
bin include lib test.c qemu-arm-static a.out qemu-arm shell.sh
Result of [system] = 0x0
But when I launch the program with chroot like this:
spy#spy-virtual-machine:/usr/arm-linux-gnueabihf$ sudo chroot ./ ./qemu-arm-static -L ./ ./a.out
The output turns out to be:
aaa
Result of [system] = 0x7f00
Apparently the system("./bin/ls") is not run as expected.
But the ./bin/ls command can be run by chroot & QEMU:
spy#spy-virtual-machine:/usr/arm-linux-gnueabihf$ sudo chroot ./ ./qemu-arm-static -L ./ ./bin/ls
bin include lib test.c qemu-arm-static a.out qemu-arm shell.sh
Now I'm totally confused. Can anybody give me a hint on this, and what can I do to get the right output of system function when using chroot command.
All command line input and output can be found in this picture:
Command line content
From man 3 system:
system() executes a command specified in command by calling /bin/sh -c
command
So you need a working shell inside the chroot in order to be able to successfully invoke system().
The following happens when this program runs in qemu-arm-static: system() results in fork() followed by exec() for the shell. When you run it without chroot this is your host (x86) shell. The shell then calls fork() followed by exec() for the bin/ls (ARM). My understanding is that it can only succeed if you have binfmt handler for the ARM ELF registered on your host. In that case registered qemu-arm gets loaded and it executes bin/ls.
When you do the same thing in the chroot the host shell is not accessible, so system() results in exec() call for the bin/sh (ARM). It looks like your binfmt handler is not accessible inside the chroot, and because of that loading bin/sh fails and error status is returned from system().
You can check registered binfmt handlers in the /proc/sys/fs/binfmt_misc
I have following 2 commands in powershell script file, but second command did not wait till first command gets executed.
cmd.exe /c "msiexec /i c:\Temp\mysql.msi /quiet"
cd "C:\Program Files (x86)\MySQL\MySQL Installer for Windows"
note: first command installing mysql installer at location C:\Program Files (x86)\MySQL\MySQL Installer for Windows"...
In second command, i used cd to go to at directory C:\Program Files (x86)\MySQL\MySQL Installer for Windows"
Your PowerShell script does not know what the cmd.exe command is going to execute but it does wait for cmd.exe to finish.
The problem is that cmd.exe is not waiting for msiexec before returning.
If you wish to wait for msiexec to finish before moving on to your second command then call msiexec yourself using Start-Process with the -Wait parameter:
Start-Process -Wait -FilePath msiexec -ArgumentList "/i c:\Temp\mysql.msi /quiet"
I'm trying it write a window batch file to perform several tasks in series, However, it always stops after tie first command in the script.
I am use this this batch file code:
start cmd /k cd %CD%mysql\bin && mysqld --install
I want to use this batch file command and install the MySQL but it run only only one command
You have the following command in your batch file:
start cmd /k cd %CD%mysql\bin && mysqld --install
Lets break it down into smaller pieces.
start start a program, command or batch script (opens in a new window.)
cmd /k cd %CD%mysql\bin run `cd %CD%mysql\bin and then return to the cmd prompt.
&& if the above succeeds then run the next command
mysqld --install run mysqld --install if start cmd /k cd %CD%mysql\bin succeeded
The second part will never run as the first part returned to the command prompt.
Try the following batch file instead:
cd %CD%mysql\bin
mysqld --install
Note the variable CD must be assigned a sensible value, otherwise cd %CD%mysql\bin will fail.
Seems you have a lot of layers here: both start and cmd /c (which I think you'd prefer over cmd /k for use in a batch file).
What's wrong with just cd %CD%\mysql\bin && mysqld --install? This worked fine for me when I attempted to run notepad.exe thus: cd /d %WINDIR%\System32 && notepad (note the additional '\' character here, just in case ... an extra backslash won't hurt if env var CD already has one). For that matter, I'll bet %CD%\mysql\bin\mysqld --install would work just fine.
However, just in case you want the extra cruft – or, more likely, need it for some other functionality you're not showing. Using just cmd:
cmd /c "cd %CD%\mysql\bin && mysqld --install"
using just start:
start "" "cd %CD%\mysql\bin && mysqld --install"
I'd put a solution using both start and cmd, but you just don't need it.
BTW, if you can't just call %CD%\mysql\bin\mysqld --install directly, I'd look into using pushd instead of cd, so that you can call popd at the end of your overall script ... it's just good form to put your script user back in the directory in which they started.
I have a VB script which converts a csv file into xls. When this VB script is run in cmd prompt, it requires 2 arguments: path of csv file which is needed to be converted, and path of xls file where it is to be saved:
D:\csv2xlx.vbs D:\sample.csv D:\converted.xls
I want this to be executed using tcl by calling cmd prompt. When I write:
exec cmd.exe /c start D:\csv2xls.vbs D:\sample.csv D:\converted.xls
It gives an error. Can anybody suggest what is the problem?
The key problem you've probably got is that those backslashes are getting interpreted by Tcl instead of getting passed through. The fix is to use forward slashes and then process the filenames with file nativename during the exec:
exec cmd.exe /c start \
[file nativename D:/csv2xls.vbs] [file nativename D:/sample.csv] \
[file nativename D:/converted.xls]
Alternatively, use \\ instead of \ in those filenames. Or put them in braces.
exec cmd.exe /c start D:\\csv2xls.vbs D:\\sample.csv D:\\converted.xls
exec cmd.exe /c start {D:\csv2xls.vbs} {D:\sample.csv} {D:\converted.xls}
My machine no longer have VBScript on it, so I cannot test this out. Try:
exec cscript.exe D:\\csv2xls.vbs D:\\sample.csv D:\\converted.xls
Update: make double backslashes per Donal's suggestion.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I have installed Google Chrome in Ubuntu 10.10. When I try to use in normal user, it is working fine.
Now if I want to use as a root it gives the following error:
Google Chrome does not run as root
Also when I tried the following command in terminal, it opens Google Chrome:
google-chrome --user-data-dir
I need a permanent solution for this. Can anybody give me idea about this?
Run from terminal
# google-chrome --no-sandbox --user-data-dir
or
Open the file opt/google/chrome/google-chrome and replace
exec -a "$0" "$HERE/chrome" "$#"
to
exec -a "$0" "$HERE/chrome" "$#" --user-data-dir --no-sandbox
It's working for chrome version 49 in CentOS 6. Chrome will give warning also.
First solution:
1. switch off Xorg access control: xhost +
2. Now start google chrome as normal user "anonymous" :
sudo -i -u anonymous /opt/google/chrome/chrome
3. When done browsing, re-enable Xorg access control:
xhost -
More info : Howto run google-chrome as root
Second solution:
1. Edit the file /opt/google/chrome/google-chrome
2. find exec -a "$0" "$HERE/chrome" "$#"
or exec -a "$0" "$HERE/chrome" "$PROFILE_DIRECTORY_FLAG" \ "$#"
3. change as
exec -a "$0" "$HERE/chrome" "$#" --user-data-dir ”/root/.config/google-chrome”
Third solution:
Run Google Chrome Browser as Root on Ubuntu Linux systems
Go to /opt/google/chrome.
Open google-chrome.
Append current home for data directory. Replace this:
exec -a "$0" "$HERE/chrome" "$#"
With this:
exec -a "$0" "$HERE/chrome" "$#" --user-data-dir $HOME
For reference visit site this site, “How to run chrome as root user in Ubuntu.”
i followed these steps
Step 1. Open /etc/chromium/default file with editor
Step 2. Replace or add this line
CHROMIUM_FLAGS="--password-store=detect --user-data-dir=/root/chrome-profile/"
Step 3. Save it..
Thats it.... Start the browser...
I tried this with Kali linux, Debian, CentOs 7,And Ubuntu
(Permanent Method)
Edit the file with any text editor (I used Leafpad) Run this code your terminal leafpad/opt/google/chrome/google-chrome
(Normally its end line) find exec -a "$0" "$HERE/chrome" "$#"
or exec -a "$0" "$HERE/chrome" "$PROFILE_DIRECTORY_FLAG" \ "$#"
change as exec -a "$0" "$HERE/chrome" "$#" --no-sandbox --user-data-dir
(Just Simple Method)
Run This command in your terminal
$ google-chrome --no-sandbox --user-data-dir
Or
$ google-chrome-stable --no-sandbox --user-data-dir
Just replace following line
exec -a "$0" "$HERE/chrome" "$#"
with
exec -a "$0" "$HERE/chrome" "$#" --user-data-dir
all things will be right.
It no longer suffices to start Chrome with --user-data-dir=/root/.config/google-chrome. It simply prints Aborted and ends (Chrome 48 on Ubuntu 12.04).
You need actually to run it as a non-root user. This you can do with
gksu -wu chrome-user google-chrome
where chrome-user is some user you've decided should be the one to run Chrome. Your Chrome user profile will be found at ~chrome-user/.config/google-chrome.
BTW, the old hack of changing all occurrences of geteuid to getppid in the chrome binary no longer works.
STEP 1: cd /opt/google/chrome
STEP 2: edit google-chrome file. gedit google-chrome
STEP 3: find this line: exec -a "$0" "$HERE/chrome" "$#".
Mostly this line is in the end of google-chrome file.
Comment it out like this : #exec -a "$0" "$HERE/chrome" "$#"
STEP 4:add a new line at the same place.
exec -a "$0" "$HERE/chrome" "$#" --user-data-dir
STEP 5: save google-chrome file and quit. And then you can use chrome as root user. Enjoy it!
Chrome can run as root (remember to use gksu when doing so) so long as you provide it with a profile directory.
Rather than type in the profile directory every time you want to run it, create a new bash file (I'd name it something like start-chrome.sh)
#/bin/bash
google-chrome --user-data-dir="/root/chrome-profile/"
Rember to call that script with root privelages!
$ gksu /root/start-chrome.sh