How to use Linqpad to run a command with path and confirmations - cmd

I wanted to make a quick linqpad script to run a tfpt command that undoes unmodified files.
Syntax is like this:
"c:\myProject> tfpt uu . /noget /recursive"
So first I need to change the path to c:\myProject.
Secondly I need to run the command "tfpt uu . /noget /recursive".
And finally I need to confirm the undo.
Can this be done with linqpad's Util.Cmd... if so how?

Managed to do it like so (made it a one liner).
Util.Cmd("echo y |tfpt uu C:\\myProject /noget /recursive");

Yes you can! With the latest bits from the beta version http://www.linqpad.net/Beta.aspx you get an utility called lprun.exe. The syntax is straighforward:
Usage: lprun [<options>] <scriptfile> [<script-args>]
options: (all case-insensitive)
-format={text|html|htmlfrag|csv|csvi} Output format. csvi=invariant CSV.
-cxname=<connection-name> Sets/overrides a script's connection.
-lang=<language> Sets/overrides a script's language.
-warn Writes compiler warnings (to stderr).
-optimize Enables compiler optimizations.
-nunuget Freshens NuGet references to latest.
scriptfile: Path to script. If it's a .linq file, -lang & -cxname are optional.
script-args: Args following <script-filepath> are passed to the script itself.
Examples:
lprun TestScript.linq
lprun TestScript.linq > results.txt
lprun script1.linq | lprun script2.linq
lprun -format=csv script.linq HelloWorld
obviously you need to create a proper LINQPad script within the language of your choice, and yes, Util.Cmd() is the way to go
HTH

Related

CMake: How to add a custom variable for user macro with a value that depends on build configuration?

I use CMake version 3.16.
I tried the following:
set_property(TARGET ${PLUGIN_NAME} PROPERTY VS_GLOBAL_FR_VERSION
$<$<CONFIG:Debug2017>:"2017">
$<$<CONFIG:Release2017>:"2017">
$<$<CONFIG:Debug2018>:"2018">
$<$<CONFIG:Release2018>:"2018">
$<$<CONFIG:Debug2019>:"2019">
$<$<CONFIG:Release2019>:"2019">
)
And it kind of worked...
This variable (FR_VERSION) is supposed to be used in a script that is launched after build. This is how it looks:
add_custom_command(TARGET ${PLUGIN_NAME} POST_BUILD
COMMAND echo $(FR_VERSION)
COMMENT "This command will copy files to dist"
VERBATIM
)
In Visual Studio, however, we got the following:
echo $<$<CONFIG:Debug2017>:"2017">;$<$<CONFIG:Release2017>:"2017">;$<$<CONFIG:Debug2018>:"2018">;$<$<CONFIG:Release2018>:"2018">;$<$<CONFIG:Debug2019>:"2019">;$<$<CONFIG:Release2019>:"2019">
which fails to execute with the error message:
"The syntax of the command is incorrect."
If I don't try to set a different value for different build configs like this:
set_target_properties(${MAYA_PLUGIN_NAME} PROPERTIES VS_GLOBAL_FR_MAYA_VERSION "2018")
then the post-build script is generated as expected. (But this is not acceptable to me, because I need different parameter values for different build configurations).
I would appreciate any advice at this point.
Some target properties support generator expressions, while others do not. The documentation for a property will explicitly say that generator expressions are supported. Take the COMPILE_FEATURES property, for example:
Contents of COMPILE_FEATURES may use “generator expressions” with the syntax $<...>.
The documentation for VS_GLOBAL_<variable> does not have such language. Thus, as suggested, you can put the generator expression directly in the add_custom_command() call, which is supported:
add_custom_command(TARGET ${PLUGIN_NAME} POST_BUILD
COMMAND echo $<$<CONFIG:Debug2017>:"2017">
$<$<CONFIG:Release2017>:"2017">
$<$<CONFIG:Debug2018>:"2018">
$<$<CONFIG:Release2018>:"2018">
$<$<CONFIG:Debug2019>:"2019">
$<$<CONFIG:Release2019>:"2019">
COMMENT "This command will copy files to dist"
)

Is there a way to compile Pascal program and put the generated files in a specific folder?

So I am trying to compile Pascal programs and everything is find; however, I would like to put the generated files after each compilation is a separated folder. I am looking of something like this: fpc "Destination Folder" "program.pas".
Thanks
From Alphabetical listing of command line options
-FE<x> Set exe/unit output path to <x>
-FU<x> Set unit output path to <x>, overrides -FE
So something like fpc program.pas -FEc:\output should work. I don't have fpc installed so I cannot verify. If you try it and get errors that you can't work through post them.
This one works for me:
fpc hello.pas -o"Web/hello.cgi"
I was using ubuntu, notice there is no space between the argument -o and the beginning of the path "Web/..."

What is the `#Name#` in command line?

I'm looking for Tsung source code. There is a line like following in file tsung.sh.in:
ERL_OPTS=" $ERL_DIST_PORTS -smp auto +P $MAX_PROCESS +A 16 +K true #ERL_OPTS# "
What does the #ERL_OPTS# mean?
This seems to be something that gets substituted by autoconf during the build process.
Generally, a .in file gets preprocessed by some build script. Autoconf uses #IDENTIFIER# to indicate the place where the actual value has to be put in. The preprocessed version loses the .in extension, thus generating tsung.sh in this particular case.

Using CMake, how can I concat files and install them

I'm new to CMake and I have a problem that I can not figure out a solution to. I'm using CMake to compile a project with a bunch of optional sub-dirs and it builds shared library files as expected. That part seems to be working fine. Each of these sub-dirs contains a sql file. I need to concat all the selected sql files to one sql header file and install the result. So one file like:
sql_header.sql
sub_dir_A.sql
sub_dir_C.sql
sub_dir_D.sql
If I did this directly in a make file I might do something like the following only smarter to deal with only the selected sub-dirs:
cat sql_header.sql > "${INSTALL_PATH}/somefile.sql"
cat sub_dir_A.sql >> "${INSTALL_PATH}/somefile.sql"
cat sub_dir_C.sql >> "${INSTALL_PATH}/somefile.sql"
cat sub_dir_D.sql >> "${INSTALL_PATH}/somefile.sql"
I have sort of figured out pieces of this, like I can use:
LIST(APPEND PACKAGE_SQL_FILES "some_file.sql")
which I assume I can place in each of the sub-dirs CMakeLists.txt files to collect the file names. And I can create a macro like:
CAT(IN "${PACKAGE_SQL_FILES}" OUT "${INSTALL_PATH}/somefile.sql")
But I am lost between when the CMake initially runs and when it runs from the make install. Maybe there is a better way to do this. I need this to work on both Windows and Linux.
I would be happy with some hints to point me in the right direction.
You can create the concatenated file mainly using CMake's file and function commands.
First, create a cat function:
function(cat IN_FILE OUT_FILE)
file(READ ${IN_FILE} CONTENTS)
file(APPEND ${OUT_FILE} "${CONTENTS}")
endfunction()
Assuming you have the list of input files in the variable PACKAGE_SQL_FILES, you can use the function like this:
# Prepare a temporary file to "cat" to:
file(WRITE somefile.sql.in "")
# Call the "cat" function for each input file
foreach(PACKAGE_SQL_FILE ${PACKAGE_SQL_FILES})
cat(${PACKAGE_SQL_FILE} somefile.sql.in)
endforeach()
# Copy the temporary file to the final location
configure_file(somefile.sql.in somefile.sql COPYONLY)
The reason for writing to a temporary is so the real target file only gets updated if its content has changed. See this answer for why this is a good thing.
You should note that if you're including the subdirectories via the add_subdirectory command, the subdirs all have their own scope as far as CMake variables are concerned. In the subdirs, using list will only affect variables in the scope of that subdir.
If you want to create a list available in the parent scope, you'll need to use set(... PARENT_SCOPE), e.g.
set(PACKAGE_SQL_FILES
${PACKAGE_SQL_FILES}
${CMAKE_CURRENT_SOURCE_DIR}/some_file.sql
PARENT_SCOPE)
All this so far has simply created the concatenated file in the root of your build tree. To install it, you probably want to use the install(FILES ...) command:
install(FILES ${CMAKE_BINARY_DIR}/somefile.sql
DESTINATION ${INSTALL_PATH})
So, whenever CMake runs (either because you manually invoke it or because it detects changes when you do "make"), it will update the concatenated file in the build tree. Only once you run "make install" will the file finally be copied from the build root to the install location.
As of CMake 3.18, the CMake command line tool can concatenate files using cat. So, assuming a variable PACKAGE_SQL_FILES containing the list of files, you can run the cat command using execute_process:
# Concatenate the sql files into a variable 'FINAL_FILE'.
execute_process(COMMAND ${CMAKE_COMMAND} -E cat ${PACKAGE_SQL_FILES}
OUTPUT_VARIABLE FINAL_FILE
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
)
# Write out the concatenated contents to 'final.sql.in'.
file(WRITE final.sql.in ${FINAL_FILE})
The rest of the solution is similar to Fraser's response. You can use configure_file so the resultant file is only updated when necessary.
configure_file(final.sql.in final.sql COPYONLY)
You can still use install in the same way to install the file:
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/final.sql
DESTINATION ${INSTALL_PATH})

Programming a Filter/Backend to 'Print to PDF' with CUPS from any Mac OS X application

Okay so here is what I want to do. I want to add a print option that prints whatever the user's document is to a PDF and adds some headers before sending it off to a device.
I guess my questions are: how do I add a virtual "printer" driver for the user that will launch the application I've been developing that will make the PDF (or make the PDF and launch my application with references to the newly generated PDF)? How do I interface with CUPS to generate the PDF? I'm not sure I'm being clear, so let me know if more information would be helpful.
I've worked through this printing with CUPS tutorial and seem to get everything set up okay, but the file never seems to appear in the appropriate temporary location. And if anyone is looking for a user-end PDF-printer, this cups-pdf-for-mac-os-x is one that works through the installer, however I have the same issue of no file appearing in the indicated directory when I download the source and follow the instructions in the readme. If anyone can get either of these to work on a mac through the terminal, please let me know step-by-step how you did it.
The way to go is this:
Set up a print queue with any driver you like. But I recommend to use a PostScript driver/PPD. (A PostScript PPD is one which does not contain any *cupsFilter: ... line.):
Initially, use the (educational) CUPS backend named 2dir. That one can be copied from this website: KDE Printing Developer Tools Wiki. Make sure when copying that you get the line endings right (Unix-like).
Commandline to set up the initial queue:
lpadmin \
-p pdfqueue \
-v 2dir:/tmp/pdfqueue \
-E \
-P /path/to/postscript-printer.ppd
The 2dir backend now will write all output to directory /tmp/pdfqueue/ and it will use a uniq name for each job. Each result should for now be a PostScript file. (with none of the modifications you want yet).
Locate the PPD used by this queue in /etc/cups/ppd/ (its name should be pdfqueue.ppd).
Add the following line (best, near the top of the PPD):
*cupsFilter: "application/pdf 0 -" (Make sure the *cupsFilter starts at the very beginning of the line.) This line tells cupsd to auto-setup a filtering chain that produces PDF and then call the last filter named '-' before it sends the file via a backend to a printer. That '-' filter is a special one: it does nothing, it is a passthrough filter.
Re-start the CUPS scheduler:sudo launchctl unload /System/Library/LaunchDaemons/org.cups.cupsd.plist
sudo launchctl load /System/Library/LaunchDaemons/org.cups.cupsd.plist
From now on your pdfqueue will cause each job printed to it to end up as PDF in /tmp/pdfqueue/*.pdf.
Study the 2dir backend script. It's simple Bash, and reasonably well commented.
Modify the 2dir in a way that adds your desired modifications to your PDF before saving on the result in /tmp/pdfqueue/*.pdf...
Update: Looks like I forgot 2 quotes in my originally prescribed *cupsFilter: ... line above. Sorry!
I really wish I could accept two answers because I don't think I could have done this without all of #Kurt Pfeifle 's help for Mac specifics and just understanding printer drivers and locations of files. But here's what I did:
Download the source code from codepoet cups-pdf-for-mac-os-x. (For non-macs, you can look at http://www.cups-pdf.de/) The readme is greatly detailed and if you read all of the instructions carefully, it will work, however I had a little trouble getting all the pieces, so I will outline exactly what I did in the hopes of saving someone else some trouble. For this, the directory with the source code is called "cups-pdfdownloaddir".
Compile cups-pdf.c contained in the src folder as the readme specifies:
gcc -09 -s -lcups -o cups-pdf cups-pdf.c
There may be a warning: ld: warning: option -s is obsolete and being ignored, but this posed no issue for me. Copy the binary into /usr/libexec/cups/backend. You will likely have to the sudo command, which will prompt you for your password. For example:
sudo cp /cups-pdfdownloaddir/src/cups-pdf /usr/libexec/cups/backend
Also, don't forget to change the permissions on this file--it needs root permissions (700) which can be changed with the following after moving cupd-pdf into the backend directory:
sudo chmod 700 /usr/libexec/cups/backend/cups-pdf
Edit the file contained in /cups-pdfdownloaddir/extra/cups-pdf.conf. Under the "PDF Conversion Settings" header, find a line under the GhostScript that reads #GhostScript /usr/bin/gs. I did not uncomment it in case I needed it, but simply added beneath it the line Ghostscript /usr/bin/pstopdf. (There should be no pre-cursor # for any of these modifications)
Find the line under GSCall that reads #GSCall %s -q -dCompatibilityLevel=%s -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -sOutputFile="%s" -dAutoRotatePage\
s=/PageByPage -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode -dPDFSETTINGS=/prepress -c .setpdfwrite \
-f %s Again without uncommenting this, under this I added the line GSCall %s %s -o %s %s
Find the line under PDFVer that reads #PDFVer 1.4 and change it to PDFVer, no spaces or following characters.
Now save and exit editing before copying this file to /etc/cups with the following command
sudo cp cups-pdfdownloaddir/extra/cups-pdf.conf /etc/cups
Be careful of editing in a text editor because newlines in UNIX and Mac environments are different and can potentially ruin scripts. You can always use a perl command to remove them, but I'm paranoid and prefer not to deal with it in the first place.
You should now be able to open a program (e.g. Word, Excel, ...) and select File >> Print and find an available printer called CUPS-PDF. Print to this printer, and you should find your pdfs in /var/spool/cups-pdf/yourusername/ by default.
*Also, I figured this might be helpful because it helped me: if something gets screwed up in following these directions and you need to start over/get rid of it, in order to remove the driver you need to (1) remove the cups-pdf backend from /usr/libexec/cups/backend (2) remove the cups-pdf.conf from /etc/cups/ (3) Go into System Preferences >> Print & Fax and delete the CUPS-PDF printer.
This is how I successfully set up a pdf backend/filter for myself, however there are more details, and other information on customization contained in the readme file. Hope this helps someone else!

Resources