I need use shell to pass the passphrase from a file, and want the comment line can read the passphrase from this file, --passphrase-fd is not working for me. It's always output an error "can not find the file". I debug the output and input files, and they are correct. Is might be the passphrase.cat file, but I checked, there is no problem in the file. Any problem in the comment line??
my code as follows and thanks for any help:
Shell(pgp & "--passphrase -fd 0 <C:\Temp\test.txt" & " -output " & output & "--decrypt " & input & """", AppWinStyle.Hide, True) ' the error happens here.
End If
''' The error as follows:
''' Unable to complete the request: System.IO.FileNotFoundException: File not found. at Microsoft.VisualBasic.Interaction.Shell(String PathName, AppWinStyle Style, Boolean Wait, Int32 Timeout) at the Sign_Click(object sender, EventArgs e) in C:\sign\MainForm.vb:line361
I expect a whole bunch of issues. For further debugging, print the command to the command line instead of executing it with Shell(...).
I guess the pgp variable does not end with a space, thus the application tries to execute something like C:\path\to\gnupg\gpg.exe--passphrase instead of C:\path\to\gnupg\gpg.exe with --passphrase parameter
The same issue likely exists between the output variable and the --decrypt command
There may not be a space inside --passphrase-fd, you wrote passphrase -fd
--output is a long parameter and requires two dashes (you wrote -output)
Finally, I figured it out. Have to use -passphrase-file passwordfile.txt to decrypted my file in the application.
Related
I want to run a bat file used to compile sass to css from within a Kotlin program, on a Windows machine. I had everything working using Runtime.exec until I switched to a Windows account that had a space in the username. From what I read, I read that using ProcessBuilder would make this easier. It seems that even with ProcessBuilder I still can't get it to work, no matter what I try.
Here is my code so far
val commands = mutableListOf(
"cmd",
"/c",
"C:\\Users\\John Doe\\VCS\\test\\tools\\sass\\windows\\dart-sass\\sass.bat",
"--no-source-map",
"C:\\Users\\John Doe\\VCS\\test\\src\\main\\sass\\global.scss",
"global.css"
)
val processBuilder = ProcessBuilder(commands)
val process = processBuilder.start()
...
The error I get is 'C:\Users\John' is not recognized as an internal or external command, operable program or batch file. It doesn't help if I surround the strings that have spaces with \".
If I remember correctly, all windows files and folders that have a space in the name have a matching short name in the old 8.3 format replacing additional space and other characters with a tilde (~) and a number.
So whatever is returning you the path for the .bat and .sscs files could return the full filename in that format?
Doesn't solve the problem but avoids it instead, I admit.
Also means you won't get busted when someone puts a space in the filename (OK, unlikely, but still something better to deal with from the start).
Consider something along the lines of the top 2 answers on this superuser thread
This is actually a Windows cmd issue. The question here shows that in cmd, in addition to quoting the file paths, you also have to quote the entire part of the command line text after the /c switch.
I don't know if this is the best way to do it in ProcessBuilder, but I was able to get it to work with the following code.
"cmd.exe",
"/c",
"\"\"C:/Users/John Doe/VCS/test/tools/sass/windows/dart-sass/sass.bat\" "
+ "--no-source-map "
+ "\"C:/Users/John Doe/VCS/test/src/main/sass/global.scss\" "
+ "\"global.css\"\""
I am trying to prompt the user of my .jl file to enter user entered multiple destinations.
Basically I need the user to give an input & an output. I know in java you would use a scanner, or accept arguments when it is compiled in the command line. I am fine with either option. From what I have found looking through the Julia Documentation I think I could accomplish the first way of assigning a variable to the readline function.
(String)in = (String)Readline(STDIN)
From my understanding the variable 'in' should now contain a String of the user's input. I am encountering an error, in that when I compile my .jl code, because my command prompt does not stop to read user input, and just finishes reading the .jl code.
The first item to note in the code in your question is:
(String)in = (String)Readline(STDIN)
Julia 1.0.0 now uses stdin instead of STDIN.
Next, the (String) typecasting is not something you need or want to do in Julia.
Thus your code could read (though we get an error):
julia> in = readline(stdin)
This is a test.
ERROR: cannot assign variable Base.in from module Main
So variable in is in conflict with a Julia Base.in variable. Just use a another variable name.
julia> response = readline(stdin)
This is a test.
"This is a test"
This code is now working, but it has no prompt. Your answer provides an example input function with a prompt which you defined like this:
julia> function input(prompt::AbstractString="")
print(prompt)
return chomp(readline())
end
input (generic function with 2 methods)
The chomp function removes a single trailing \n newline character from the input string. Docs here.
Example use of the function here:
julia> input_file = input("Please enter input file name: ")
Please enter input file name: Data.txt
"Data.txt"
julia> output_file = input("Please enter output file name: ")
Please enter output file name: Output.txt
"Output.txt"
Command Line Args Method
As the docs point out, to just print out the arguments given to a script, you can do something like this:
println("Arguments passed to ", PROGRAM_FILE, ":")
for arg in ARGS
println(arg)
end
Here is an example of above code running on the Windows command line:
c:\OS_Prompt>julia PrintArgs.jl Data.txt Output1.txt Output2.txt Output3.txt
Arguments passed to PrintArgs.jl:
Data.txt
Output1.txt
Output2.txt
Output3.txt
You can also print out the script file name as shown, PrintArgs.jl.
After searching & testing I found one solution and decided to reply to it here. I had to declare my own function to be able to get the program to accept user input.
function input(prompt::AbstractString="")
print(prompt)
return chomp(readline())
end
I am not sure what the chomp function does, but I know it works for what I was asking. I am still curious if you can do something in Julia similar to java and C String args[], in which you pass extra information while you are telling your command to run. Something like the following.
Julia testFile.jl goHere.txt lookHere.txt
I am making a program that uses the rasidal command to connect to a VPN server. Obviously this requires a login and this is stored in a notepad file.
Process.Start("rasdial.exe", """VPN Connection"" HardcodedUSERNAME HardCodedPassword")
This seems to work fine, however when I read this information from a notepad file and write it to the screen they are still exactly the same. Why is it that the login could be incorrect.
All I am doing is
Process.Start("rasdial.exe", """VPN Connection"" & Info")
Thanks
Your variable "info" is never used. Try it out an remove the info-variable or rename it.
Do you have to double-quote "VPN Connection"? So try this one:
Process.Start("rasdial.exe", """VPN Connection"" " & Info)
And can you please tell me what your info-variable contains.
What I need to do:
I have a path (copied from a working shortcut) to an .exe that I need to launch from my vb.net application. Following Path:
"C:\Program Files (x86)\Citrix\ICA client\pnagent.exe" /CitrixShortcut: (2) /QLaunch "Farm1:ADS # Citrix"
My problem:
I cannot figure out how to do this. My best guess was
Process.Start("cmd", "/k " & path)
But that always ends up with cmd giving back
'C:\Program' is not recognized as an internal or external ...
I know this is due to the path not being properly escaped, but I can't figure out how to do it properly. I know about using Double-Doubblequotes ("") but I couldn't get that work either.
If anyone can point me to a maybe better way to do this than Process.Start() I'd be very happy aswell!
I think the Process.Start() overload you want is
Process.Start(program, args).
... which would give you
Process.Start("C:\Program Files (x86)\Citrix\ICA client\pnagent.exe", "/CitrixShortcut: (2) /QLaunch ""Farm1:ADS # Citrix"" ")
Edit / Clarification:
cmd /k launches the command shell (aka "DOS prompt") but keeps it open after running the specified command (as opposed to cmd /c which executes the command and then closes the shell).
You typically only start cmd if you want to execute a shell built-in like DIR or COPY.
Dim MyProcess as string = "C:\Program Files (x86)\Citrix\ICA client\pnagent.exe"
Dim MyArgs as string = "/CitrixShortcut: (2) /QLaunch ""Farm1:ADS # Citrix"""
Process.Start(MyProcess, MyArgs)
I was originally trying to run an executable (tftpd32.exe) from Expect with the following command, but for some unknown reason it would hanged the entire script:
exec c:/tftpd32.351/tftpd32.exe
So, decided to call a batch file that will start the executable.
I tried to call the batch file with the following command, but get an error message stating windows cannot find the file.
exec c:/tftpd32.351/start_tftp.bat
I also tried the following, but it does not start the executable:
spwan cmd.exe /c c:/tftpd32.351/start_tftp.bat
The batch file contains this and it run ok when I double click on it:
start tftpd32.exe
Any help would be very much appreciated.
Thanks
The right way to run that program from Tcl is to do:
set tftpd "c:/tftpd32.351/tftpd32.exe"
exec {*}[auto_execok start] "" [file nativename $tftpd]
Note that you should always have that extra empty argument when using start (due to the weird way that start works; it has an optional string in quotes that specifies the window title to create, but it tends to misinterpret the first quoted string as that even if that leaves it with no mandatory arguments) and you need to use the native system name of the executable to run, hence the file nativename.
If you've got an older version of Tcl inside your expect program (8.4 or before) you'd do this instead:
set tftpd "c:/tftpd32.351/tftpd32.exe"
eval exec [auto_execok start] [list "" [file nativename $tftpd]]
The list command in that weird eval exec construction adds some necessary quoting that you'd have trouble generating otherwise. Use it exactly as above or you'll get very strange errors. (Or upgrade to something where you don't need nearly as much code gymnastics; the {*} syntax was added for a good reason!)