MS Word commands from command line - command-line

I need to start MS Word from command line. Now, I pass these commands /q /n /mFilePrintDefault /mFileExit to it. In this case, I need manually press "No" on "save yes/no" dialog at the end (to close Word). What commands need to pass, to skip this (without saving or with saving doc) and automatically close Word?

In Word, create a macro in Normal.dotm using this code:
Sub CloseWithoutSaving()
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
Application.Quit
End Sub
Then pass /q /n /mFilePrintDefault /mCloseWithoutSaving

I assume you are trying to print the document from the command line. You might want to do it the same way MS does it with right-click print. You can see details on this here:
http://www.robvanderwoude.com/ddecommandline.php

Related

Copy Command Prompt's content to clipboard

I'm looking for a solution to copy the command prompt's current content to the clipboard. I know something similar is possible by redirecting the output or using clip but I'm looking for something else. I'm looking for a command which copies the entire content of the command prompt window to the clipboard/a file anytime when it's called(not just the output of one command). It's quite easy to do manually by selecting everything and press ctrl-c but I need a command for this.
Basically it should achieve the same as doskey /history > somefile.txt but saving the output of the commands too.
Is something like this possible?
you can use simple java program , to get the entire content of the command prompt and out it into a String variable or write it to txt file

Is there a way to edit last Octave command and /or script typed in Octave CLI

typing and executing a single line command in octave cli is simple.
for example a=1.
If one wants to edit this command and execute it again it is possible by navigating the history with the up/down keys.
But when executing a multi line command-script, one can still navigate to a single line and edit it, but how to execute the all script again, without going line by line in the history and "enter" the line?
for example:
for i=1:6
a(i) = i;
end
Is there a way to open the all script in an editor, edit, and re-execute it?
Yes there is, via the history command.
E.g. history -q 3 will display the last 3 commands -- the -q switch means do not prepend line numbers, such that the output is copy-pasteable.
You can also use the -w switch to redirect the output to a file, which you could then modify in your editor and call as a script, as you suggest.
If you're using the GUI, you can also use the history pane to highlight the lines you're interested in (in the order that you want them!), and paste directly into the editor window.

How achieve a two line Prompt?

In the batch language of Microsoft's CMD.EXE console window, I never liked having my command start at the far right, after a long display of the directory path. So in my Control Panel → System → Advanced System Settings → Environment Variables I saved the following assignment, where $_ is like a Soft Return:
PROMPT=[$P\]$_$+$G$S
The displayed prompt was two lines like this:
[C:\Temp\]
>
(The $+ tracks pushd and popd, the fancier than chdir commands. $S is space. By the way, the ^ character a line wrap/continuation character in batch, just as backtick ` is in PowerShell.)
Now I want the same-ish two line prompt in PowerShell. There is good news and bad news.
The good news is I can achieve that in my open PowerShell window by typing at the > prompt:
function prompt {'[' + $(get-location) + '\] SHIFTENTER > '
(By SHIFTENTER I mean press Shift+Enter, what I think might be called a "soft return"?)
....... BAD NEWS, PROBLEM ......
I want to put the above function prompt ... line into my profile PowerShell script, namely Microsoft.PowerShell_profile.ps1 (at path $Profile). But how?
Notepad.exe has no support for Shift+Enter.
MS Word understands Shift+Enter, but when I SaveAs .txt, and then examine with Notepad++, I see a plain CR-LF (meaning \r\n, 0x0d 0x0a).
Notepad++ menu Edit → Character Panel enables me to insert special ASCII characters into my .txt / .ps1 file, such as 0x0b called VT (for "vertical tab"). But despite some claims on websites, VT is not behaving like a Soft Return when I use it in my function prompt ... profile .ps1 file (I also run the profile .ps1 script to retest).
Can the prompt I want be established by a profile .ps1 script?
The PowerShell equivalent of your batch-prompt is:
function prompt { "[$(Get-Location)\]`r`n$("+"*(Get-Location -Stack).Count)>" }
#`r`n is just a shorter way of writing [System.Environment]::NewLine
Add it to the profile to suits your needs:
AllUsersAllHosts:
C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
AllUsersPowerShell:
C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
AllUsersISE:
C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShellISE_profile.ps1
CurrentUserAllHosts:
C:\Users\username\Documents\WindowsPowerShell\profile.ps1
CurrentUserPowerShell:
C:\Users\username\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
CurrentUserISE:
C:\Users\username\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1

Lua (Command Line) remain open after execution

I have searched far and wide for this but I cannot seem to find it. Is there any way to execute a Lua script via double clicking it (to execute it in Lua (Command Line)) and keep it open after execution?
For example:
print("Hello World")
This code compiles and runs, however if I double click on hello.luait runs and closes immediately without leaving my text on screen. I want something more like this, but without having to go to Command Prompt, changing directory a bunch of times, typing lua file.lua, etc.:
Add io.read() at the end of your script.
The easiest way would be to just add a 'pause' at the end of your script:
print 'Hello World'
os.execute 'pause'

CMD Batch File With Muliple Inputs

I am trying to automate a command that prompts the users for their pin, the command in question;
tpmvscmgr.exe create /name "vSmartcard" /pin prompt /adminkey default generate
at this point you press enter, the next thing you see is
Enter Pin:
You enter the pin and press enter, then you get asked to confirm the pin before pressing enter again.
How can I automate this in a batch file, or in powershell? I haven't been able to find any commands that work in a similar way to even get a start on it.
I am not sure if the trick below work with your particular program; but even in this case, if the program prompts for an additional input it must be placed inside the parenheses next to the pin number. Perhaps this is enough for your needs...
#echo off
(
echo pinnum
echo pinnum
) | tpmvscmgr.exe create /name "vSmartcard" /pin prompt /adminkey default generate