I have a code which will un-hide all files present in the removable drive
//buffer is the removable drive letter
PWSTR show = L"/k attrib -s -r -h *.* /s /d /l ";
ShellExecute(NULL,L"open",L"cmd.exe",show,buffer,SW_HIDE);
This code works successfully but after performing this operation I cannot eject my removable drive.
It shows the following message
Even when I close my program it shows this message. When seeing the task manager I found that my drive I:\ is running in the background what should I do now to solve this
The switch /k makes cmd.exe run a command then sit there waiting for further instructions.
Your shell window is still there, in the background, hidden, sitting on I:.
Replace /k with /c.
/C Run Command and then terminate
/K Run Command and then return to the CMD prompt.
This is useful for testing, to examine variables
(http://ss64.com/nt/cmd.html)
Related
I know one can run two commands in one line in Windows CMD like this:
dir & echo foo
But how could one run two commands parallel? I also know that one can achieve this by using START. But then you have to put those commands into a batch file. I would want to launch them parallel from the command line itself.
What I would like to achieve is something like this:
set NODE_ENV=development&& nodemon -e js,jsx,cjsx,css,scss,html,coffee --watch ./app/ server/server.js & set NODE_ENV=development&& node server/hotLoadServer.js
If I run the commands separately in separate windows, they work perfect. But I cannot seem to get them run as a one liner in one cmd prompt. What happens is, the first one is run, the second is not. The first one will remain open, and the second one is never executed.
This executes two tasks in parallel and open one window for each:
# powershell
start ping google.com; start ping example.com
# cmd
start ping google.com & start ping example.com
This does the same, but the /B option prevents any new window from opening (in cmd):
start /B ping google.com & start ping example.com
I didn't find any direct equivalent in powershell, although starting this in powershell does the trick:
cmd /C 'start /B ping google.com & start /B ping example.com'
Note also that powershell's Start-Job cmdlet allows users to start background jobs.
You can run parallel threads in one cmd session. use 'cmd' command with /c parameter, it will Carries out the command specified by string and then stops.
e.g
cmd /c echo done
for more reference :https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx?mfr=true
I try to create a simple UI which runs a command prompt in the background (but the windows console must not disappear) while clicking on each button, resp.
But before, I try something like system("start dir"); to see if the button works.
Here is the problem: when I click on the left button the windows console appear and don't exit unit I close it. But this only work with system("start dir");. If I change dir to ipconfig (or another call-function) the windows console will appear for a second and the exit. I tried something like system("PAUSE"); or getch(); etc, but it doesn't work.
Why does this command work with dir but not with another command?
There is a fundamental difference between DIR and IPCONFIG, the DIR command is built into the command processor (aka shell), IPCONFIG is a separate program stored in c:\windows\system32.
When you type START /? at the command line then you can see why it treats them differently:
If it is an internal cmd command or a batch file then
the command processor is run with the /K switch to cmd.exe.
This means that the window will remain after the command
has been run.
If it is not an internal cmd command or batch file then
it is a program and will run as either a windowed application
or a console application.
The alternative is to ask the command processor to execute the command and exit afterwards. You do with the /c option:
system("cmd.exe /c dir");
Or simpler yet, since system() automatically passes off the job to the command processor:
system("dir");
Just stop using start :)
I have a image processing project in C++ using opencv. The program runs correctly and I get the desired output. However, I have some messages that I print out using the cout command. When I run the program using the terminal (./myprogram) the messages are displayed correctly. When I double click the executable file I get only the output (in my case a new video is created) But I do get the messages. How do I get the program to automatically prompt the messages when it is not run from the terminal.
PS: I use ubuntu 14.04
Create a script like this, lets call it run.sh:
#!/bin/sh
cd work_dir
./myProgram
read -r -p "Press any key..." key
Then do:
xterm -e run.sh
and make your desktop shortcut run this command instead of the program directly.
I run below code in vc.
system("#echo off");
system("set a=3");
system("echo %a%");
system("pause");
but it display as '%a%', but I require display as '3'.
How Can I make it?
Thanks very much for your help.
Create the "tmp.bat" file:
#echo off
set a=3
echo %a%
pause
and then call the
system("cmd /c tmp.bat")
The thing is that system() call creates a "clean" environment where the "a" variable has not been set (in the "echo %a%" call).
To convert the sequence of commands into something "executable" one might use some special tool, not the "VC".
Look for http://www.autoitscript.com/site/autoit/ and similar tools.
For a start, every single one of those commands runs independently of the other. By the time you try to echo %a%, the set for it (from the previous call to system) has been long forgotten. So, it's effectively the same as if you had opened up a brand new cmd window and typed:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\Pax> echo %a%
%a%
C:\Documents and Settings\Pax> _
You will probably need to place all those instructions into a single cmd file then run:
system ("cmd /c c:\\full\\path\\to\my\\script.cmd");
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")