Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6880347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:57:45+00:00 2026-05-27T04:57:45+00:00

I need to process a file of certain types with external command line program

  • 0

I need to process a file of certain types with external command line program accepting single argument (filename) and then use file modified by this program either open modified file or accept output of command line program as data source for file.

Any way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:57:45+00:00Added an answer on May 27, 2026 at 4:57 am

    If you just want this to work when you open the file with C-x C-f, then you can probably just attach your behaviour to find-file, but deeper down I believe insert-file-contents is what eventually reads files in.

    A cursory look doesn’t seem to show any appropriate hook, so you could look at doing this with before advice.

    (defadvice insert-file-contents
      (before my-before-insert-file-contents-advice)
      "Process files externally before reading them."
      (let ((filename (expand-file-name (ad-get-arg 0))))
        (message "About to read file %s" filename)
        ;; your code here.
    
        ;; ;; stupid unsafe example:
        ;; (let ((file (shell-quote-argument filename))
        ;;       (tempfile (shell-quote-argument (make-temp-file "some-prefix-"))))
        ;;   (shell-command (format "sort %s >%s" file tempfile))
        ;;   (shell-command (format "mv %s %s" tempfile file)))
        ))
    (ad-activate 'insert-file-contents)
    

    You might like to elaborate on your requirements, in case you don’t actually need to clobber the original file? (which I think is a horrendous idea, frankly; I certainly wouldn’t use code like this!)

    For example, you could read in the original file, process it within the buffer (maybe using shell-command-on-region with the replace flag), and set the buffer as unmodified. That way you are only likely to save the changes made by the shell command if you make other edits to the file, and the mere act of loading the file into an editor hasn’t actually modified it.

    In any case, I trust you’ll implement sensible backup processes into your code, and will be plenty paranoid when testing!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a way to make a process keep a certain file open forever.
I need to process a large file, around 400K lines and 200 M. But
I'm writing a config file and I need to define if the process expects
I need to identify some locations in a file where certain markers might be.
I made a program in XNA 4.0 that should simulate an assembly line process.
I need to continuously read a log file to detect certain patterns. How can
I am writing a java program on windows platform. I need to compress certain
this might be quite a newbie question, but i need to process a certain
I need to read a text based log file to check for certain contents
I need to identify the P(rocess) ID of an executing batch file from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.