Wikipedia:Reference desk/Archives/Computing/2019 May 13

= May 13 =

pgrep doesn't work unless redirected
when I run this script: while true; do pgrep firefox echo $? > ~/1.txt sleep 1 done , I can see  returning success (0), but only as long the terminal window I started the script in, is open. If I  the script,   still returns success, but then when I close the terminal window, it begins returning 1 (no process matched.) This doesn't happen if I redirect   (or the whole   block) to a file. Is it supposed to do that and Why is this (something with PTYs?)?
 * 1) !/bin/bash

Aecho6Ee (talk) 09:18, 13 May 2019 (UTC)
 * Yes, if you disown a process, its standard output will still be directed to your terminal. Trying to write to an unassigned PTY will give you the return code 1 as well:
 * 
 * $ pgrep bash >/dev/pts/999; echo $?
 * bash: /dev/pts/999: Permission denied
 * 1
 * -Chelyabinsk Breeze (talk) 12:29, 15 May 2019 (UTC)
 * Thank you so much! Aecho6Ee (talk) 11:48, 16 May 2019 (UTC)

PDF viewer that opens files as read-only (OS setting) (Windows 10)
XY problem disclaimer: what I seek to achieve is to have an IDE where I edit a LaTeX file and compile it, and another window where I view the PDF as it is compiled. If you try that with Adobe Reader (and some other PDF viewers), those open PDFs with write permissions (to add annotations etc.); therefore, compiling the LaTeX document will fail if the viewer is open, because (I assume) the viewer takes the lock on the document (the exact error is path\to\MiKTeX 2.9\tex/generic/pgf/libraries\pgflibraryfadings.code.tex:17: I can't write on file `nameofthefile.pdf'. Please type another file name for output). IDE is VS Code, changing it is not an option, and the preview capabilities are not good (need to split the window, meaning the font size on the PDF is small).

Hence: I am looking for a way to open a PDF in read-only mode with an easy "refresh" mechanism. (I searched for a command-line option to Adobe Reader but turned up nothing.) Web searches are polluted by folks asking how to show a pdf to their users without allowing it to be saved (spoiler: it's not possible), and I am kinda tired of trying random PDF viewers when the feature I want is absolutely not documented.

Bonus points for a solution that does not need admin rights (I have to bother IT if I need them). Tigraan Click here to contact me 11:58, 13 May 2019 (UTC)
 * Probably an obvious question but what happens if you flag the file read only before opening and remove the flag after it was opened? Regards So  Why  12:20, 13 May 2019 (UTC)
 * Changing the file permissions might work, but (1) I would need a bit more code to do that automagically: as the PDF is recreated at each compile, the compilation workflow must be "make writable, compile, make read-only"; (certainly feasible, but I expect it to be a major pain) and (2) a viewer-side solution seems cleaner and not asking for much (actually, the more basic software are more likely to need only read permission by default). Tigraan Click here to contact me 15:52, 13 May 2019 (UTC)
 * There should be no reason to remove the flag. I do what is suggested whenever I am writing. I write Latex in Kate and click the compile button. I have the PDF open in Okular on another screen. When the Latex compiles, Okular automatically loads the changes. The issue is the PDF reader locking the document. I use Okular because it doesn't lock the PDF file by default. So, the question is very simple: Is there a PDF reader in Windows that does not lock the PDF file? 12.207.168.3 (talk) 13:32, 13 May 2019 (UTC)
 * Evince--Phil Holmes (talk) 13:56, 13 May 2019 (UTC)
 * In Linux, Evince does not lock the PDF file. That looks like a good candidate for Windows. 12.207.168.3 (talk) 14:27, 13 May 2019 (UTC)
 * Thanks. Installing Evince on Windows seems non-obvious, but I will persist. Tigraan Click here to contact me 15:52, 13 May 2019 (UTC)
 * When I installed Evince on my W10 box, I just downloaded the msi from https://www.fosshub.com/Evince.html --TrogWoolley (talk) 12:01, 14 May 2019 (UTC)
 * I didn't suggest Okular because I thought a KDE application would be hard to install on Windows. I didn't realize that Evince was strictly a Gnome application. It is even harder to install on Windows. I feel the issue here is the market. Developers treat Windows users different than they treat Linux users. In Linux, the idea is that you get an application that does one thing very well. In Windows, you get an application that does what you want acceptably, but it does a lot of other junk that you don't like because someone else wants it. So, finding a very simple PDF viewer in Windows appears to be harder than picking one of the dozens of very simple PDF viewers for Linux. 12.207.168.3 (talk) 11:53, 14 May 2019 (UTC)
 * Until Poettering stuck his neb in and screwed up init, that is. Martin of Sheffield (talk) 12:22, 14 May 2019 (UTC)


 * Update: Evince can be installed on Windows... but my company's antivirus has decided not to let me run it. I am seriously considering making the jump to "build it from sources".
 * FTR: if you follow the instructions on the Evince website, you will get nowhere (it will lead you to a package with no instal instructions and no way to automatically pull dependencies). Instead, install MYSYS2 which has a decent manual and an evince package (pacman -Ss evince to find its name). (I get that making Windows ports of Linux-developed applications is not very sexy, but I hate it nonetheless.) Tigraan Click here to contact me 15:31, 14 May 2019 (UTC)
 * Just a bit of advice: it will be easier to run a full-blown instance of your favorite Linux, and install your Linux application software, inside a virtual machine like VirtualBox, rather than to try to build linux application software from source against Windows. Although it is surely possible to build from source, it is a pretty advanced procedure and you're surely straying very far from your original purpose.  If you're already doing a lot of "*-nix"-style work, like using TeX, then using a VM is a good way to keep yourself closer to what other people on the web are doing - your workflow inside the VM will exactly match the workflow of other Linux users.  Of course, you may proceed as you see fit...
 * Nimur (talk) 15:39, 14 May 2019 (UTC)
 * Windows 10 is making it easier with many Linux tools built in. Unfortunately, it is currently console-only. No form of an X emulator of any kind. If they add graphics, you should be able to install and run Linux applications natively in Windows. 12.207.168.3 (talk) 15:57, 14 May 2019 (UTC)


 * Maybe I'm missing something, but is there some reason not to simply use a Windows native PDF reader that does not lock the file rather than going through the complicated process of trying to compile some Linux PDF reader for Windows? A simple search for 'non locking pdf reader' finds 5 different threads (well probably more I stopped at 5), all of which recommend Sumatra PDF [//superuser.com/questions/599442/pdf-viewer-that-handles-live-updating-of-pdf-doesnt-lock-the-file] [//forums.adobe.com/thread/2345245] [//tex.stackexchange.com/questions/288470/how-do-i-open-pdf-in-adobe-reader-dc-without-locking-the-file-from-being-updated] [//stackoverflow.com/questions/4910029/possible-to-make-adobe-reader-not-hold-a-file-lock-on-windows] [//latex.org/forum/viewtopic.php?t=9218]. It is apparently (from our article and a quick look at the repository [//github.com/sumatrapdfreader/sumatrapdf/blob/master/COPYING] linked to on the official site [//www.sumatrapdfreader.org/free-pdf-reader.html]) GPLv3 if you want to inspect the code. If Sumatra PDF doesn't work for you, at least one of the sources suggested Evince. The official developers [//wiki.gnome.org/Apps/Evince/Downloads] recommend 2 sources for Windows that are MingW based. Unfortunately one of them is semi dead. You'll have to navigate the site and work out where what you want has moved if anywhere. The other works [//repo.msys2.org/mingw/i686/], but the package xz I downloaded doesn't really. (Well the binary is doesn't run due to missing DLLs.) I think you have to download something else to provide the missing DLLs. Possibly exploring the site will explain what you need. This also has some other recommendations. If neither of these work for you, it strikes me that most browsers can now natively open PDFs and it's unlikely they will lock the file. A quick test of Edge, Firefox and Chrome suggests none of them do. At least I was able to delete the file despite it being open in these browsers. I noticed that browsers was also recommend in at least one of those threads. If none of these work for you, it may be worth exploring other options but I'm somewhat unclear from the questions and info provides why it's necessary to get so complicated. (In particular, what problems are there with Sumatra PDF or why not try it?) Nil Einne (talk) 23:25, 14 May 2019 (UTC)
 * Whops I missed the part about Evince being rejected by AV software. If this is a restricted environment, I'm not sure if you'll be allowed to run Sumatra PDF either although there is a portable version and it is signed. That said, I'm unsure why your environment will block MingW stuff but allow stuff you compile yourself. I haven't looked into it, but you could consider compiling Sumatra PDF yourself if that's the reason you rejected it. (I admit I'm still confused why it wasn't tried.) I think it needs Visual Studio, but you may be able to use Visual Studio Express if that's available to you. BTW, I just tested Sumatra PDF and confirmed I can delete my PDF. (I should mentioned that opening it in Adobe Reader does not allow me to.) Barring all else, I assume you have at least one browser with a built in PDF reader already installed? I admit I find their PDF reader GUIs a little limiting, but like with Sumatra PDF, it's unclear why they weren't considered or were rejected. (In this case, perhaps it just didn't occur to you and you missed it in the searches since it's not recommended much.) Nil Einne (talk) 23:37, 14 May 2019 (UTC)


 * P.S. As a final solution I wonder if Universal Windows Platform programs lock files. I was going to try this, unfortunately Microsoft killed off that Reader program they were trying to convinced everyone to use [//www.microsoft.com/en-us/p/reader/9wzdncrfhwg5], in favour of Edge. And my attempts to install some random PDF readers from the Microsoft Store failed since it seems to be acting up. In any case, this solution seems problematic given your environment as I'm assuming most IT admins will say something like "you want to do what?" when you ask them about installing a UWP program from the Microsoft Store. Nil Einne (talk) 23:43, 14 May 2019 (UTC)


 * P.P.S. I don't program and I'm not an expert on the nature of Windows software design, but I don't believe File locking should be confused with a program acting in a read only fashion. A program which allows editing of a file may choose not to lock a file with the associated risks thereof. (Some text editors and hex editors do this. The smarter ones warn you when a file is changed.) A program which does not allow editing may prefer to keep normal file locks in place, especially if it doesn't interpret the whole file at the beginning and wants to avoid the problems associated with the file changing while it's using it. In other words, to be clear, what you're looking for is a PDF reader that doesn't lock the file rather than a PDF reader that is read only. Nil Einne (talk) 00:11, 15 May 2019 (UTC)

Sumatra PDF did the job. My question was pretty much a duplicate of, but my Google-fu was weak and couldn't find it (the most important keyword was "lock"). Tigraan Click here to contact me 11:16, 15 May 2019 (UTC)
 * I'm happy you already found a solution, but I wanted to add that TexWorks does this automatically - you get the tex editor in one window and the "refreshable" PDF in the other. The PDF refreshes every time you run latex. 65.201.170.154 (talk) 14:44, 17 May 2019 (UTC)