right click command line help

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
davzo
Posts: 2
Joined: 20 Jan 2020 08:28

right click command line help

#1 Post by davzo » 20 Jan 2020 08:37

hello
I am using a command line with some sofware like this:

C:\Program Files\SC\sc.exe /c pdf "%1" "%1".pdf

this should convert a file like example.plt to example.pdf
but instrad I am getting the converted file as :example.plt.pdf

I need it to convert it as a final result to:example.pdf
I tried to use this command below, and nothing happens at all.
I read that d=drive, p=path' n=filename

C:\Program Files\SC\sc.exe /c pdf "%1" "%~dpn1".pdf

can someone help on how to do this right so the files it creates will be example.pdf and not example.plt.pdf

Thanks

ShadowThief
Expert
Posts: 954
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: right click command line help

#2 Post by ShadowThief » 21 Jan 2020 04:24

What program are you using? sc.exe is already an executable that's built into Windows that controls system services, so I'm having a hard time Googling what you're using.

Just guessing wildly here because I don't have all of the information that I need, your ending quote is in the wrong place. Instead of "%~dpn1".pdf you should be using "%~dpn1.pdf" but without knowing what program you're using and what arguments it takes, it's hard to say. For all I know you only need to provide the basename and extension for the output file instead of the whole path.

davzo
Posts: 2
Joined: 20 Jan 2020 08:28

Re: right click command line help

#3 Post by davzo » 21 Jan 2020 08:19

Hi
Thanks for the anwsew. tried it but it won't work.
I am using Viecompanion viewer software :
C:\Program Files\Software Companions\ViewCompanion Premium\viewcompanion.exe /c pdf "%1" "%1".pdf
(the above is what I am currently using but it converts files from example.plt to --> example.plt.pdf
and I need it do convert to only example.pdf

Thanks

Squashman
Expert
Posts: 4153
Joined: 23 Dec 2011 13:59

Re: right click command line help

#4 Post by Squashman » 21 Jan 2020 09:41

So you are using the SENDTO option of the context menu?

The syntax for the command is
ViewCompanion /c format inputfile outputfile

So ShadowThief gave you the correct syntax for using the command modifiers.

ViewCompanion /c pdf "%~1" "%~dpn1.pdf"

Eureka!
Posts: 89
Joined: 25 Jul 2019 18:25

Re: right click command line help

#5 Post by Eureka! » 21 Jan 2020 11:11

At least, you should enclose the program name - including folder - in double quotes as it contains spaces:
"C:\Program Files\Software Companions\ViewCompanion Premium\viewcompanion.exe"

Furthermore, the "%~dpn1" syntax is not supported everywhere, so it is very relevant how and where you start this, as @Squashman already pointed out.

EDIT:
Possible workaround removed as that didn't work ...

ShadowThief
Expert
Posts: 954
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: right click command line help

#6 Post by ShadowThief » 22 Jan 2020 17:31

Eureka! wrote:
21 Jan 2020 11:11
At least, you should enclose the program name - including folder - in double quotes as it contains spaces:
"C:\Program Files\Software Companions\ViewCompanion Premium\viewcompanion.exe"

Furthermore, the "%~dpn1" syntax is not supported everywhere, so it is very relevant how and where you start this, as @Squashman already pointed out.

EDIT:
Possible workaround removed as that didn't work ...
I would be very interested to know in what situations %~dpn1 won't work.

Eureka!
Posts: 89
Joined: 25 Jul 2019 18:25

Re: right click command line help

#7 Post by Eureka! » 22 Jan 2020 19:19

ShadowThief wrote:
22 Jan 2020 17:31
I would be very interested to know in what situations %~dpn1 won't work.
Windows context menu entries, for example.

Here the command is executed by the shell (Explorer) and not CMD.
Context menu entries use their own "variables" %1 and %* (and a couple of less often used ones like %L %v and %i) to pass parameters to - in this case - viewcompanion.exe.

penpen
Expert
Posts: 1809
Joined: 23 Jun 2013 06:15
Location: Germany

Re: right click command line help

#8 Post by penpen » 23 Jan 2020 04:45

If you are using a link for the sendto menue, this might help you (tested on Win10) to type into the field "target" of the link (properties; this only echoes the command lines):

Code: Select all

C:\Windows\System32\cmd.exe /V:ON /E:ON /k @for %n in (1 2) do @if %n == 2 (for %b in (!params!) do @call echo("C:\Program Files\Software Companions\ViewCompanion Premium\viewcompanion.exe" /c pdf "%~b" "%~dpnb.pdf") else set params=
If the echoed command lines are correct, then remove the "echo(" and change "/k" to "/c" (untested, but should work):

Code: Select all

C:\Windows\System32\cmd.exe /V:ON /E:ON /c @for %n in (1 2) do @if %n == 2 (for %b in (!params!) do @call "C:\Program Files\Software Companions\ViewCompanion Premium\viewcompanion.exe" /c pdf "%~b" "%~dpnb.pdf") else set params=
penpen

Post Reply