Pipe Console App to file from batch file - vb.net

I have a console app (Visual Studio - VB), it runs, it does it's job.
I also have a batch file that runs the program and everything, but I want the output of my console app to also send to a text file.
This is my current batch, which creates the text file, but nothing is in it.
Start "" "C:\Users\wrossi\Desktop\NetLogOnSysInfo Solution\NetLogOnSysInfo Project\bin\Debug\NetLogOnSysInfo Project.exe" -all >>%ComputerName%.txt
Exit
Not sure if the batch is wrong, or if I should look at my program. Also, how do I define a path so I can put the output file exactly where I want it?

"C:\Users\wrossi\Desktop\
NetLogOnSysInfo Solution\NetLogOnSysInfo Project\bin\Debug\NetLogOnSysInfo Project.exe"
-all > %ComputerName%.txt
No need to use Start.

You are pretty close to what I think you want to do:
c:\console.exe > c:\output.exe
c:\console.exe or wherever the location of your console app > redirect stdout (use >> to append) c:\output.txt or wherever you want to create the text file.
Hope this helped.
Also just in case:
type stdin.txt | console.exe > stdout.txt
In the above example you can redirect an input from stdin.txt and pipe it into console.exe then redirect the output of console.exe to stdout.txt

I found one code recently after searching alot
if u wanna run .bat file in vb or c# or simply
just add this in the same manner in which i have written
here is the code
code > C:\Users\Lenovo\Desktop\output.txt
just replace word "code" with your .bat file code or command and after that the directory of output file

Related

is there a way to use the full file path in the command line without typing it?

For example, I want to open a PDF file in the browser from the command line (just because it's much faster and I need to open many files at once) and when I use the command start [file name] from its directory it try to open it as a executable, so I need to open the browser and type the full path of the file as an attribute, is there a way to call the full path without typing it?
what I exactly need is I need the full path of a file to convert it to string (for example in the browser)
Using tab completions may help. For example, if your target file is named thisPDFisTotallyBananas.pdf and you have another file in the same folder named thisOtherPDFisNot.pdf, you could type thisP then TAB to complete the file name in the command prompt without needing to type the whole filename.

While loop files in folder

I'm relatively new to Netlogo and already struggling ;)
I have the following problem: I want my program to open a folder, check a file in that folder and afterwards remove that file from that folder. I figured the best way to do this is via a while loop, but I'm struggling to find the right syntax. Hope you all can help!
The command 'file-open' will open a file using the path provided (the string after file-open: e.g. file-open "C:\Documents\model-out.txt" will open a file titled model-out.txt in the Documents folder on the C drive.)
You can then use 'file-read' or 'file-write' to read or write to the file respectively.
The command 'file-close' will close the file, which then can be deleted with 'file-delete'.
You can also check if a file exists in a folder using the command if file-exists? "C:\Documents\model-out.txt", and if true, the file can be deleted using file-delete.
Also check the command 'set-current-directory'.
Best,

In Lua, how to print the console output into a file (piping) instead of using the standard output?

I workin' with Torch7 and Lua programming languages. I need a command that redirects the output of my console to a file, instead of printing it into my shell.
For example, in Linux, when you type:
$ ls > dir.txt
The system will print the output of the command "ls" to the file dir.txt, instead of printing it to the default output console.
I need a similar command for Lua. Does anyone know it?
[EDIT] An user suggests to me that this operation is called piping. So, the question should be: "How to make piping in Lua?"
[EDIT2] I would use this # command to do:
$ torch 'my_program' # printed_output.txt
Have a look here -> http://www.lua.org/pil/21.1.html
io.write seems to be what you are looking for.
Lua has no default function to create a file from the console output.
If your applications logs its output -which you're probably trying to do-, it will only be possible to do this by modifying the Lua C++ source code.
If your internal system has access to the output of the console, you could do something similar to this (and set it on a timer, so it runs every 25ms or so):
dumpoutput = function()
local file = io.write([path to file dump here], "w+")
for i, line in ipairs ([console output function]) do
file:write("\n"..line);
end
end
Note that the console output function has to store the output of the console in a table.
To clear the console at the end, just do os.execute( "cls" ).

How to redirect output of a running process to a file in Linux Shell

I am trying a bit of experiments with airmon-ng script in Linux. Meanwhile i want to redirect output of a process "airodump-ng mon0" to a file. I can see the instantaneous output on the screen. The feature of this process is that it won't stop execution(actually it is a script to scan for AP and clients, it will keep on scanning) unless we use ctrl+c.
Whenever i try
airodump-ng mon0 > file.txt
i won't get the output in the file.
My primary assumption is that the shell will write it to the file only after completing the execution. But in the above case i stopped the execution(as the execution won't complete).
So to generalize i can't pipe the output of a running process to a file. How can i do that?
Or is there any alternative way to stop the execution of the process(for example after 5 seconds) and redirect the current output to a file?
A process may send output to standard output or standard error to get it to the terminal. Generally, the former is for information and the latter for errors, but in some cases, a process may mix them up.
I'm supposing that in your case, the standard error is being used. To get both of these to the output file, you can use:
airmon-ng mon0 > file.txt 2>&1
This says to send standard output to file.txt and to reroute 2 (which is the file id for standard error) into 1 (the file id for standard output) so that it also goes to the file.

Providing input files during compilation

To run a CUDA C program we build the program and then run the binary file created from the command line as
/.prgm_bin_file
If for example the program needs some input files like for programs to image processing, I want to supply the data files or the input files at the time of compilation.
How can I do that. How the above command can be edited to give the required files.
Thanks in advance.
If your program opens data files to use for input, it's using some file I/O API to do so. For example, one possible method is to use fopen.
Just to use it as an example, if you are using fopen, it expects a filename (a character string) passed as the first parameter.
Many programs will take this filename from a the command line used to invoke the program. But there's nothing that would prevent you from hard-coding the filename:
fp=fopen("mydata", "r");
In that case, the program would always attempt to open the file mydata
But if your program is already designed to use the filename as a command line parameter, it's not clear that this is any more useful than just invoking your program that way:
./prgm_bin_file mydata