How do I exit a command prompt with Power Automate? - command-line-arguments

I'm using Power Automate to open a specific file with VS Code. I'm doing this by running command prompt with the following command line arguments:
cd /d <file's folder directory>&&code <file name>&&exit /b"
This opens the file but an empty command prompt stays open, is there a way I could fix this?
If not, is there an alternative way to open a specific file with VS Code using Power Automate?

Related

Katacoda Scenarios not recognizing open command in the terminal

I am learning to create my own scenario in katacoda. I want to open a file that I created in the katacoda editor, but it's not letting me use the open command in my background.sh file. This is what I have in it so far:
touch my-project/new.py
echo "print('Hello World')" >> my-project/new.py
open new.py
This creates the python file, but it does not open it. I tried running open new.py in the terminal, but it gives me an error
bash: open: command not found
I can click on it in the file tree to open it, but I want it to open automatically. What other command can I use to open it in the katacoda editor?
After messaging support, you are not able to put code in a file that is opened on start in Katacoda. You can embed links that will add code when the user clicks on it, but that's a different task. Katacoda does not support the "open" command, but you can use vim or nano.

How do I make a cmd script that once it is run, remains open and accepts new commands?

I want to make a cmd script that performs an action but then remains open and I can type new commands.
I have failed to find the proper terms to google as my knowledge of shell is almost zero.
thank you!
You can specify a command shell to run a specific command during start-up using the /k switch. E.g.
cmd /k C:\InitialScript.bat
The command shell would execute the C:\InitialScript.bat batch file and remain open for the user to type further commands.
If you want to create an icon for users to use then create a shortcut and use the following as the target:
%WINDIR%\System32\cmd.exe /K C:\InitialScript.bat
If you already have a command shell window open, then just use the following which will run the batch file in the context of the existing shell:
C:\InitialScript.bat

Run a Command Prompt command from Desktop Shortcut

Is it possible to create a desktop shortcut that, when pressed, will open command prompt and run a pre-defined command?
Create A Shortcut That Opens The Command Prompt & Runs A Command:
Yes! You can create a shortcut to cmd.exe with a command specified after it. Alternatively you could create a batch script, if your goal is just to have a clickable way to run commands.
Steps:
Right click on some empty space in Explorer, and in the context menu go to "New/Shortcut".
When prompted to enter a location put either:
"C:\Windows\System32\cmd.exe /k your-command" This will run the command and keep (/k) the command prompt open after.
or
"C:\Windows\System32\cmd.exe /c your-command" This will run the command and the close (/c) the command prompt.
Notes:
Tested, and working on Windows 8 - Core X86-64 September 12 2014
If you want to have more than one command, place an "&" symbol in between them. For example: "C:\Windows\System32\cmd.exe /k command1 & command2".
Yes, make the shortcut's path
%comspec% /k <command>
where
%comspec% is the environment variable for cmd.exe's full path, equivalent to C:\Windows\System32\cmd.exe on most (if not all) Windows installs
/k keeps the window open after the command has run, this may be replaced with /c if you want the window to close once the command is finished running
<command> is the command you wish to run
The solutions turned out to be very simple.
Open text edit
Write the command, save as .bat.
Double click the file created and the command automatically starts running in command-prompt.
Create new text file on desktop;
Enter desired commands in text file;
Rename extension of text file from ".txt" --> ".bat"
Yes. One option you have is to create a batch file containing the command
cmd -c {your command}
or
cmd -k {your command}
The shortcut will then be to this batch file.
This is an old post but I have issues with coming across posts that have some incorrect information/syntax...
If you wanted to do this with a shorcut icon you could just create a shortcut on your desktop for the cmd.exe application. Then append a /K {your command} to the shorcut path.
So a default shorcut target path may look like "%windir%\system32\cmd.exe", just change it to %windir%\system32\cmd.exe /k {commands}
example: %windir%\system32\cmd.exe /k powercfg -lastwake
In this case i would use /k (keep open) to display results.
Arlen was right about the /k (keep open) and /c (close)
You can open a command prompt and type "cmd /?" to see your options.
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx?mfr=true
A batch file is kind of overkill for a single command prompt command...
Hope this helps someone else
I tried this, all it did was open a cmd prompt with "cmd -c (my command)"
and didn't actually run it. see below.
C:\windows\System32>cmd -c (powercfg /lastwake)
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\windows\System32>
***Update
I changed my .bat file to read "cmd /k (powercfg /lastwake)" and it worked.
You can also leave out the () and it works too.
You can also create a shortcut on desktop that can run a specific command or even a batch file by just typing the command in "Type the Location of Item" bar in create shortcut wizard
Right click on Desktop.
Enter the command in "Type the Location of Item" bar.
Double click the shortcut to run the command.
Found detailed Instructions here
Using the Drag and Drop method
From the windows search bar type in cmd to pull up the windows bar operation.
When the command line option is shown, right click it and select Open File Location.
The file explorer opens and the shortcut link is highlighted in the folder. If it is not highlighted, then select it.
Hold down the Control key and using the mouse drag the shortcut to the desktop. If you don't see Copy to Desktop while dragging and before dropping, then push down and hold the Control key until you see the message.
Drop the link on the desktop.
Change properties as needed.

How to open a command prompt window in ruby script and have an interactive session

I have a requirement where i need to open command prompt and run a bat file, this bat file will ask for the user to enter a choice 2 to 3 times, how to automate this in ruby in windows.
Am able to open command prompt using
system("start cmd.exe")
After this I need to change directory and then i need to run the file present in c://temp//dat.bat, through ruby script.
Please let me know how to automate all these operations.
cmd_line = "cmd.exe /c \"cd #{directory}&&#{bat_file}\""
system(cmd_line) # if you're not interested in the output
Should do it.

How to execute makecab/f command from notepad?

How can I run a command that is located in a folder using a text file. Here is the command
C:\Program Files\GAPS\XML Forms\CSurvey\temp>makecab/f directories.txt
currently I am able to run upto this path "C:\Program Files\GAPS\XML Forms\CSurvey\temp" using notepad by using the following as a notepad content
cmd /k "cd C:\Program Files\GAPS\XML Forms\CSurvey\temp"
But i'm not able to run the makecab/f directories.txt from notepad. how to modify the notepad content so that the makecab/f directories.txt will execute automatically without manually typing the command in run window?
I assume you want to be able to run the above command using a text file?
That does not make much sense, but maybe due to your English level, I can try to answer your question
Open a new notepad text file.
Type the command you want to run:
C:\Program Files\GAPS\XML Forms\CSurvey\temp>makecab/f "C:\Program Files\GAPS\XML Forms\CSurvey\temp\directories.txt"
Notice that you need to specify full path for directories.txt because since you will run this command from somewhere else, you would need to make sure the path is correct.
Save the file as SomeFileName.bat notice that you must save it with .bat not .txt otherwise, the file will not be executable. Also, make sure Windows is not hiding known extensions to avoid having your file named: YourFileName.bat.txt.
There are two ways of solving your problem.
If you want the command window to remain open after finishing the job, then change this line:
cmd /k "cd C:\Program Files\GAPS\XML Forms\CSurvey\temp"
to this one:
cmd /k "cd C:\Program Files\GAPS\XML Forms\CSurvey\temp & makecab/f directories.txt"
Alternatively, though, you could have the command window close automatically upon completing the batch script. In that case replace your command with these two lines:
cd C:\Program Files\GAPS\XML Forms\CSurvey\temp
makecab/f directories.txt
Note the absence of cmd /k. The command window will automatically open when you start the script and it will stay open while the script is executing.

Resources